From 333a6cc37005668f614252d3c58fedad4ef50e1d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 4 Feb 2012 11:03:44 +0000 Subject: [PATCH] Fixed rounding issue on spent hours column in CSV export (#10150). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8764 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/issues_helper.rb | 2 +- test/functional/issues_controller_test.rb | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index b061840fb..29444e703 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -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 diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index eb75f073d..f423cc5d1 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -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) -- 2.39.5