Makes all time entry columns available in the CSV export.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11442 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2013-02-19 20:41:54 +00:00
parent af92686c62
commit f8c649320f
4 changed files with 30 additions and 210 deletions

View File

@@ -22,7 +22,9 @@ class TimelogControllerTest < ActionController::TestCase
fixtures :projects, :enabled_modules, :roles, :members,
:member_roles, :issues, :time_entries, :users,
:trackers, :enumerations, :issue_statuses,
:custom_fields, :custom_values
:custom_fields, :custom_values,
:projects_trackers, :custom_fields_trackers,
:custom_fields_projects
include Redmine::I18n
@@ -546,186 +548,17 @@ class TimelogControllerTest < ActionController::TestCase
assert assigns(:items).first.is_a?(TimeEntry)
end
def test_index_all_projects_csv_export
def test_index_csv_all_projects
Setting.date_format = '%m/%d/%Y'
get :index, :format => 'csv'
assert_response :success
assert_equal 'text/csv; header=present', @response.content_type
assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
assert @response.body.include?("\n04/21/2007,Redmine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
assert_equal 'text/csv; header=present', response.content_type
end
def test_index_csv_export
def test_index_csv
Setting.date_format = '%m/%d/%Y'
get :index, :project_id => 1, :format => 'csv'
assert_response :success
assert_equal 'text/csv; header=present', @response.content_type
assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
assert @response.body.include?("\n04/21/2007,Redmine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
end
def test_index_csv_export_with_multi_custom_field
field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'list',
:multiple => true, :possible_values => ['value1', 'value2'])
entry = TimeEntry.find(1)
entry.custom_field_values = {field.id => ['value1', 'value2']}
entry.save!
get :index, :project_id => 1, :format => 'csv'
assert_response :success
assert_include '"value1, value2"', @response.body
end
def test_csv_big_5
user = User.find_by_id(3)
user.language = "zh-TW"
assert user.save
str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
str_big5 = "\xa4@\xa4\xeb"
if str_utf8.respond_to?(:force_encoding)
str_utf8.force_encoding('UTF-8')
str_big5.force_encoding('Big5')
end
@request.session[:user_id] = 3
post :create, :project_id => 1,
:time_entry => {:comments => str_utf8,
# Not the default activity
:activity_id => '11',
:issue_id => '',
:spent_on => '2011-11-10',
:hours => '7.3'}
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
t = TimeEntry.find_by_comments(str_utf8)
assert_not_nil t
assert_equal 11, t.activity_id
assert_equal 7.3, t.hours
assert_equal 3, t.user_id
get :index, :project_id => 1, :format => 'csv',
:from => '2011-11-10', :to => '2011-11-10'
assert_response :success
assert_equal 'text/csv; header=present', @response.content_type
ar = @response.body.chomp.split("\n")
s1 = "\xa4\xe9\xb4\xc1"
if str_utf8.respond_to?(:force_encoding)
s1.force_encoding('Big5')
end
assert ar[0].include?(s1)
assert ar[1].include?(str_big5)
end
def test_csv_cannot_convert_should_be_replaced_big_5
user = User.find_by_id(3)
user.language = "zh-TW"
assert user.save
str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
if str_utf8.respond_to?(:force_encoding)
str_utf8.force_encoding('UTF-8')
end
@request.session[:user_id] = 3
post :create, :project_id => 1,
:time_entry => {:comments => str_utf8,
# Not the default activity
:activity_id => '11',
:issue_id => '',
:spent_on => '2011-11-10',
:hours => '7.3'}
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
t = TimeEntry.find_by_comments(str_utf8)
assert_not_nil t
assert_equal 11, t.activity_id
assert_equal 7.3, t.hours
assert_equal 3, t.user_id
get :index, :project_id => 1, :format => 'csv',
:from => '2011-11-10', :to => '2011-11-10'
assert_response :success
assert_equal 'text/csv; header=present', @response.content_type
ar = @response.body.chomp.split("\n")
s1 = "\xa4\xe9\xb4\xc1"
if str_utf8.respond_to?(:force_encoding)
s1.force_encoding('Big5')
end
assert ar[0].include?(s1)
s2 = ar[1].split(",")[8]
if s2.respond_to?(:force_encoding)
s3 = "\xa5H?"
s3.force_encoding('Big5')
assert_equal s3, s2
elsif RUBY_PLATFORM == 'java'
assert_equal "??", s2
else
assert_equal "\xa5H???", s2
end
end
def test_csv_tw
with_settings :default_language => "zh-TW" do
str1 = "test_csv_tw"
user = User.find_by_id(3)
te1 = TimeEntry.create(:spent_on => '2011-11-10',
:hours => 999.9,
:project => Project.find(1),
:user => user,
:activity => TimeEntryActivity.find_by_name('Design'),
:comments => str1)
te2 = TimeEntry.find_by_comments(str1)
assert_not_nil te2
assert_equal 999.9, te2.hours
assert_equal 3, te2.user_id
get :index, :project_id => 1, :format => 'csv',
:from => '2011-11-10', :to => '2011-11-10'
assert_response :success
assert_equal 'text/csv; header=present', @response.content_type
ar = @response.body.chomp.split("\n")
s2 = ar[1].split(",")[7]
assert_equal '999.9', s2
str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
if str_tw.respond_to?(:force_encoding)
str_tw.force_encoding('UTF-8')
end
assert_equal str_tw, l(:general_lang_name)
assert_equal ',', l(:general_csv_separator)
assert_equal '.', l(:general_csv_decimal_separator)
end
end
def test_csv_fr
with_settings :default_language => "fr" do
str1 = "test_csv_fr"
user = User.find_by_id(3)
te1 = TimeEntry.create(:spent_on => '2011-11-10',
:hours => 999.9,
:project => Project.find(1),
:user => user,
:activity => TimeEntryActivity.find_by_name('Design'),
:comments => str1)
te2 = TimeEntry.find_by_comments(str1)
assert_not_nil te2
assert_equal 999.9, te2.hours
assert_equal 3, te2.user_id
get :index, :project_id => 1, :format => 'csv',
:from => '2011-11-10', :to => '2011-11-10'
assert_response :success
assert_equal 'text/csv; header=present', @response.content_type
ar = @response.body.chomp.split("\n")
s2 = ar[1].split(";")[7]
assert_equal '999,9', s2
str_fr = "Fran\xc3\xa7ais"
if str_fr.respond_to?(:force_encoding)
str_fr.force_encoding('UTF-8')
end
assert_equal str_fr, l(:general_lang_name)
assert_equal ';', l(:general_csv_separator)
assert_equal ',', l(:general_csv_decimal_separator)
end
assert_equal 'text/csv; header=present', response.content_type
end
end