]> source.dussan.org Git - redmine.git/commitdiff
Fixed rounding issue on spent hours column in CSV export (#10150).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 4 Feb 2012 11:03:44 +0000 (11:03 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 4 Feb 2012 11:03:44 +0000 (11:03 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8764 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/issues_helper.rb
test/functional/issues_controller_test.rb

index b061840fbd70a461984496f03121a3167a44b298..29444e703ddf9181c4d69e8b19bb934fc34bd429 100644 (file)
@@ -329,7 +329,7 @@ module IssuesHelper
             elsif value.is_a?(Time)
               format_time(value)
             elsif value.is_a?(Float)
-              value.to_s.gsub('.', decimal_separator)
+              ("%.2f" % value).gsub('.', decimal_separator)
             else
               value
             end
index eb75f073d72e508293c20a3060b901f115f5c2c5..f423cc5d153a815de0f6ecc1e16dd9ea55f139ac 100644 (file)
@@ -329,6 +329,17 @@ class IssuesControllerTest < ActionController::TestCase
     assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
   end
 
+  def test_index_csv_with_spent_time_column
+    issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column')
+    TimeEntry.generate!(:project_id => issue.project_id, :issue_id => issue.id, :hours => 7.33)
+
+    get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
+    assert_response :success
+    assert_equal 'text/csv', @response.content_type
+    lines = @response.body.chomp.split("\n")
+    assert_include "#{issue.id},#{issue.subject},7.33", lines
+  end
+
   def test_index_csv_with_all_columns
     get :index, :format => 'csv', :columns => 'all'
     assert_response :success
@@ -433,7 +444,7 @@ class IssuesControllerTest < ActionController::TestCase
                   :set_filter => 1
       assert_equal 'text/csv', @response.content_type
       lines = @response.body.chomp.split("\n")
-      assert_equal "#{issue.id},1234.5,#{str1}", lines[1]
+      assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
 
       str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
       if str_tw.respond_to?(:force_encoding)
@@ -462,7 +473,7 @@ class IssuesControllerTest < ActionController::TestCase
                   :set_filter => 1
       assert_equal 'text/csv', @response.content_type
       lines = @response.body.chomp.split("\n")
-      assert_equal "#{issue.id};1234,5;#{str1}", lines[1]
+      assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
 
       str_fr = "Fran\xc3\xa7ais"
       if str_fr.respond_to?(:force_encoding)