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
This commit is contained in:
Jean-Philippe Lang 2012-02-04 11:03:44 +00:00
parent 2789cf2506
commit 333a6cc370
2 changed files with 14 additions and 3 deletions

View 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

View 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)