##// END OF EJS Templates
Merged r9378 from trunk....
Merged r9378 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@9399 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r8523:a6a627f4455b
r9265:1feb373c8903
Show More
time_entry_reports_controller_test.rb
307 lines | 11.1 KiB | text/x-ruby | RubyLexer
/ test / functional / time_entry_reports_controller_test.rb
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 # -*- coding: utf-8 -*-
Jean-Baptiste Barth
Use absolute paths in test/**/* requires for Ruby 1.9.2 compatibility. #4050...
r4395 require File.expand_path('../../test_helper', __FILE__)
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118
class TimeEntryReportsControllerTest < ActionController::TestCase
Jean-Philippe Lang
Dropped TimeEntryReportsController....
r7907 tests TimelogController
Toshi MARUYAMA
code layout clean up test/functional/time_entry_reports_controller_test.rb...
r7644 fixtures :projects, :enabled_modules, :roles, :members, :member_roles,
:issues, :time_entries, :users, :trackers, :enumerations,
:issue_statuses, :custom_fields, :custom_values
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118
Toshi MARUYAMA
add csv separator check to the test to export time entry csv in Traditional Chinese (#8368)...
r7829 include Redmine::I18n
Toshi MARUYAMA
add functional test to export time entry report csv encoded in Big5 on Traditional Chinese locale (#8549)...
r7691 def setup
Setting.default_language = "en"
end
Jean-Philippe Lang
Changed timelogs filters to use non-AJAX requests (#1965)....
r5177 def test_report_at_project_level
get :report, :project_id => 'ecookbook'
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Changed timelogs filters to use non-AJAX requests (#1965)....
r5177 assert_tag :form,
:attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'}
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_all_projects
get :report
assert_response :success
assert_template 'report'
Jean-Philippe Lang
Changed timelogs filters to use non-AJAX requests (#1965)....
r5177 assert_tag :form,
:attributes => {:action => "/time_entries/report", :id => 'query_form'}
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_all_projects_denied
r = Role.anonymous
r.permissions.delete(:view_time_entries)
r.permissions_will_change!
r.save
get :report
assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_all_projects_one_criteria
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 assert_not_nil assigns(:report)
assert_equal "8.65", "%.2f" % assigns(:report).total_hours
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end
def test_report_all_time
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 get :report, :project_id => 1, :criteria => ['project', 'issue']
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 assert_not_nil assigns(:report)
assert_equal "162.90", "%.2f" % assigns(:report).total_hours
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end
def test_report_all_time_by_day
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 get :report, :project_id => 1, :criteria => ['project', 'issue'], :columns => 'day'
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 assert_not_nil assigns(:report)
assert_equal "162.90", "%.2f" % assigns(:report).total_hours
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_tag :tag => 'th', :content => '2007-03-12'
end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_one_criteria
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 assert_not_nil assigns(:report)
assert_equal "8.65", "%.2f" % assigns(:report).total_hours
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 def test_report_two_criteria
get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["member", "activity"]
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 assert_not_nil assigns(:report)
assert_equal "162.90", "%.2f" % assigns(:report).total_hours
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_one_day
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["member", "activity"]
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 assert_not_nil assigns(:report)
assert_equal "4.25", "%.2f" % assigns(:report).total_hours
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_at_issue_level
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["member", "activity"]
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 assert_not_nil assigns(:report)
assert_equal "154.25", "%.2f" % assigns(:report).total_hours
Jean-Philippe Lang
Changed timelogs filters to use non-AJAX requests (#1965)....
r5177 assert_tag :form,
:attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'}
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_custom_field_criteria
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 get :report, :project_id => 1, :criteria => ['project', 'cf_1', 'cf_7']
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 assert_not_nil assigns(:report)
assert_equal 3, assigns(:report).criteria.size
assert_equal "162.90", "%.2f" % assigns(:report).total_hours
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 # Custom field column
assert_tag :tag => 'th', :content => 'Database'
# Custom field row
assert_tag :tag => 'td', :content => 'MySQL',
:sibling => { :tag => 'td', :attributes => { :class => 'hours' },
:child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
:content => '1' }}
# Second custom field column
assert_tag :tag => 'th', :content => 'Billable'
end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_one_criteria_no_result
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project']
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_template 'report'
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 assert_not_nil assigns(:report)
assert_equal "0.00", "%.2f" % assigns(:report).total_hours
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Jean-Philippe Lang
Adds "Status" to the time report criteria (#9985)....
r8523 def test_report_status_criterion
get :report, :project_id => 1, :criteria => ['status']
assert_response :success
assert_template 'report'
assert_tag :tag => 'th', :content => 'Status'
assert_tag :tag => 'td', :content => 'New'
end
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_all_projects_csv_export
Toshi MARUYAMA
code layout clean up test_report_all_projects_csv_export of test/functional/time_entry_reports_controller_test.rb...
r7663 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30",
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 :criteria => ["project", "member", "activity"], :format => "csv"
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_equal 'text/csv', @response.content_type
lines = @response.body.chomp.split("\n")
# Headers
Toshi MARUYAMA
code layout clean up test_report_all_projects_csv_export of test/functional/time_entry_reports_controller_test.rb...
r7663 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total',
lines.first
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 # Total row
assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
end
Toshi MARUYAMA
remove trailing white-spaces from test/functional/time_entry_reports_controller_test.rb....
r6492
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 def test_report_csv_export
Toshi MARUYAMA
code layout clean up test_report_csv_export of test/functional/time_entry_reports_controller_test.rb...
r7664 get :report, :project_id => 1, :columns => 'month',
:from => "2007-01-01", :to => "2007-06-30",
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 :criteria => ["project", "member", "activity"], :format => "csv"
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 assert_response :success
assert_equal 'text/csv', @response.content_type
lines = @response.body.chomp.split("\n")
# Headers
Toshi MARUYAMA
code layout clean up test_report_csv_export of test/functional/time_entry_reports_controller_test.rb...
r7664 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total',
lines.first
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 # Total row
assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
end
Toshi MARUYAMA
add functional test to export time entry report csv encoded in Big5 on Traditional Chinese locale (#8549)...
r7691
def test_csv_big_5
Setting.default_language = "zh-TW"
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
user = User.find_by_id(3)
user.firstname = str_utf8
user.lastname = "test-lastname"
assert user.save
comments = "test_csv_big_5"
te1 = TimeEntry.create(:spent_on => '2011-11-11',
:hours => 7.3,
:project => Project.find(1),
:user => user,
:activity => TimeEntryActivity.find_by_name('Design'),
:comments => comments)
te2 = TimeEntry.find_by_comments(comments)
assert_not_nil te2
assert_equal 7.3, te2.hours
assert_equal 3, te2.user_id
get :report, :project_id => 1, :columns => 'day',
:from => "2011-11-11", :to => "2011-11-11",
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 :criteria => ["member"], :format => "csv"
Toshi MARUYAMA
add functional test to export time entry report csv encoded in Big5 on Traditional Chinese locale (#8549)...
r7691 assert_response :success
assert_equal 'text/csv', @response.content_type
lines = @response.body.chomp.split("\n")
# Headers
s1 = "\xa6\xa8\xad\xfb,2011-11-11,\xc1`\xadp"
Toshi MARUYAMA
fix time entry csv last line encoding (#8549)...
r7827 s2 = "\xc1`\xadp"
Toshi MARUYAMA
add functional test to export time entry report csv encoded in Big5 on Traditional Chinese locale (#8549)...
r7691 if s1.respond_to?(:force_encoding)
s1.force_encoding('Big5')
Toshi MARUYAMA
fix time entry csv last line encoding (#8549)...
r7827 s2.force_encoding('Big5')
Toshi MARUYAMA
add functional test to export time entry report csv encoded in Big5 on Traditional Chinese locale (#8549)...
r7691 end
assert_equal s1, lines.first
# Total row
assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1]
Toshi MARUYAMA
fix time entry csv last line encoding (#8549)...
r7827 assert_equal "#{s2},7.30,7.30", lines[2]
Toshi MARUYAMA
add csv separator check to the test to export time entry csv in Traditional Chinese (#8368)...
r7829
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 'Big5', l(:general_csv_encoding)
assert_equal ',', l(:general_csv_separator)
assert_equal '.', l(:general_csv_decimal_separator)
Toshi MARUYAMA
add functional test to export time entry report csv encoded in Big5 on Traditional Chinese locale (#8549)...
r7691 end
Toshi MARUYAMA
fix malformed time entry report csv encoding in case of unable to convert (#8549)...
r7700
def test_csv_cannot_convert_should_be_replaced_big_5
Setting.default_language = "zh-TW"
str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
if str_utf8.respond_to?(:force_encoding)
str_utf8.force_encoding('UTF-8')
end
user = User.find_by_id(3)
user.firstname = str_utf8
user.lastname = "test-lastname"
assert user.save
comments = "test_replaced"
te1 = TimeEntry.create(:spent_on => '2011-11-11',
:hours => 7.3,
:project => Project.find(1),
:user => user,
:activity => TimeEntryActivity.find_by_name('Design'),
:comments => comments)
te2 = TimeEntry.find_by_comments(comments)
assert_not_nil te2
assert_equal 7.3, te2.hours
assert_equal 3, te2.user_id
get :report, :project_id => 1, :columns => 'day',
:from => "2011-11-11", :to => "2011-11-11",
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 :criteria => ["member"], :format => "csv"
Toshi MARUYAMA
fix malformed time entry report csv encoding in case of unable to convert (#8549)...
r7700 assert_response :success
assert_equal 'text/csv', @response.content_type
lines = @response.body.chomp.split("\n")
# Headers
s1 = "\xa6\xa8\xad\xfb,2011-11-11,\xc1`\xadp"
if s1.respond_to?(:force_encoding)
s1.force_encoding('Big5')
end
assert_equal s1, lines.first
# Total row
s2 = ""
if s2.respond_to?(:force_encoding)
s2 = "\xa5H?"
s2.force_encoding('Big5')
elsif RUBY_PLATFORM == 'java'
s2 = "??"
else
s2 = "\xa5H???"
end
assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1]
end
Toshi MARUYAMA
add tests to export time entry csv in French for csv separator (#8368)...
r7831
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-11',
:hours => 7.3,
: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 7.3, te2.hours
assert_equal 3, te2.user_id
get :report, :project_id => 1, :columns => 'day',
:from => "2011-11-11", :to => "2011-11-11",
Jean-Philippe Lang
Extracted time report logic from the controller....
r7906 :criteria => ["member"], :format => "csv"
Toshi MARUYAMA
add tests to export time entry csv in French for csv separator (#8368)...
r7831 assert_response :success
assert_equal 'text/csv', @response.content_type
lines = @response.body.chomp.split("\n")
# Headers
s1 = "Membre;2011-11-11;Total"
s2 = "Total"
if s1.respond_to?(:force_encoding)
s1.force_encoding('ISO-8859-1')
s2.force_encoding('ISO-8859-1')
end
assert_equal s1, lines.first
# Total row
assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1]
assert_equal "#{s2};7,30;7,30", lines[2]
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 'ISO-8859-1', l(:general_csv_encoding)
assert_equal ';', l(:general_csv_separator)
assert_equal ',', l(:general_csv_decimal_separator)
end
end
Eric Davis
Refactor: extract TimelogController#report to a new controller class...
r4118 end