diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-22 17:37:16 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-10-22 17:37:16 +0000 |
commit | 2d1866d966d94c688f9cb87c5bf3f096dffac844 (patch) | |
tree | 7a733c1cc51448ab69b3f892285305dbfb0ae15e /test/functional | |
parent | a6ec78a4dc658e3517ed682792016b6530458696 (diff) | |
download | redmine-2d1866d966d94c688f9cb87c5bf3f096dffac844.tar.gz redmine-2d1866d966d94c688f9cb87c5bf3f096dffac844.zip |
Merged rails-4.1 branch (#14534).
git-svn-id: http://svn.redmine.org/redmine/trunk@13482 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional')
24 files changed, 147 insertions, 214 deletions
diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index faf7356ea..114684b30 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -72,8 +72,8 @@ class AccountControllerTest < ActionController::TestCase end def test_login_with_suburi_should_redirect_to_back_url_param - @relative_url_root = ApplicationController.relative_url_root - ApplicationController.relative_url_root = '/redmine' + @relative_url_root = Redmine::Utils.relative_url_root + Redmine::Utils.relative_url_root = '/redmine' back_urls = [ 'http://test.host/redmine/issues/show/1', @@ -84,7 +84,7 @@ class AccountControllerTest < ActionController::TestCase assert_redirected_to back_url end ensure - ApplicationController.relative_url_root = @relative_url_root + Redmine::Utils.relative_url_root = @relative_url_root end def test_login_should_not_redirect_to_another_host @@ -99,8 +99,8 @@ class AccountControllerTest < ActionController::TestCase end def test_login_with_suburi_should_not_redirect_to_another_suburi - @relative_url_root = ApplicationController.relative_url_root - ApplicationController.relative_url_root = '/redmine' + @relative_url_root = Redmine::Utils.relative_url_root + Redmine::Utils.relative_url_root = '/redmine' back_urls = [ 'http://test.host/', @@ -115,7 +115,7 @@ class AccountControllerTest < ActionController::TestCase assert_redirected_to '/my/page' end ensure - ApplicationController.relative_url_root = @relative_url_root + Redmine::Utils.relative_url_root = @relative_url_root end def test_login_with_wrong_password diff --git a/test/functional/activities_controller_test.rb b/test/functional/activities_controller_test.rb index 49d5aff61..06c1624b0 100644 --- a/test/functional/activities_controller_test.rb +++ b/test/functional/activities_controller_test.rb @@ -127,11 +127,13 @@ class ActivitiesControllerTest < ActionController::TestCase end def test_index_atom_feed_with_one_item_type - get :index, :format => 'atom', :show_issues => '1' - assert_response :success - assert_template 'common/feed' - - assert_select 'title', :text => /Issues/ + with_settings :default_language => 'en' do + get :index, :format => 'atom', :show_issues => '1' + assert_response :success + assert_template 'common/feed' + + assert_select 'title', :text => /Issues/ + end end def test_index_should_show_private_notes_with_permission_only diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index 018f848d9..4da2f5f66 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -139,8 +139,7 @@ class AttachmentsControllerTest < ActionController::TestCase assert a.save assert_equal 'japanese-utf-8.txt', a.filename - str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" - str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding) + str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8') get :show, :id => a.id assert_response :success diff --git a/test/functional/calendars_controller_test.rb b/test/functional/calendars_controller_test.rb index e67d05dfb..01f9a8ce1 100644 --- a/test/functional/calendars_controller_test.rb +++ b/test/functional/calendars_controller_test.rb @@ -48,10 +48,10 @@ class CalendarsControllerTest < ActionController::TestCase end def test_week_number_calculation - Setting.start_of_week = 7 - - get :show, :month => '1', :year => '2010' - assert_response :success + with_settings :start_of_week => 7 do + get :show, :month => '1', :year => '2010' + assert_response :success + end assert_select 'tr' do assert_select 'td.week-number', :text => '53' @@ -65,9 +65,10 @@ class CalendarsControllerTest < ActionController::TestCase assert_select 'td.even', :text => '9' end - Setting.start_of_week = 1 - get :show, :month => '1', :year => '2010' - assert_response :success + with_settings :start_of_week => 1 do + get :show, :month => '1', :year => '2010' + assert_response :success + end assert_select 'tr' do assert_select 'td.week-number', :text => '53' diff --git a/test/functional/context_menus_controller_test.rb b/test/functional/context_menus_controller_test.rb index 6670927cd..3a18ca30a 100644 --- a/test/functional/context_menus_controller_test.rb +++ b/test/functional/context_menus_controller_test.rb @@ -56,12 +56,14 @@ class ContextMenusControllerTest < ActionController::TestCase end def test_context_menu_one_issue_by_anonymous - get :issues, :ids => [1] - assert_response :success - assert_template 'context_menus/issues' - assert_tag :tag => 'a', :content => 'Delete', - :attributes => { :href => '#', - :class => 'icon-del disabled' } + with_settings :default_language => 'en' do + get :issues, :ids => [1] + assert_response :success + assert_template 'context_menus/issues' + assert_tag :tag => 'a', :content => 'Delete', + :attributes => { :href => '#', + :class => 'icon-del disabled' } + end end def test_context_menu_multiple_issues_of_same_project diff --git a/test/functional/custom_fields_controller_test.rb b/test/functional/custom_fields_controller_test.rb index 76579d74a..0d86df204 100644 --- a/test/functional/custom_fields_controller_test.rb +++ b/test/functional/custom_fields_controller_test.rb @@ -112,7 +112,7 @@ class CustomFieldsControllerTest < ActionController::TestCase end def test_new_js - get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'list'}, :format => 'js' + xhr :get, :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'list'}, :format => 'js' assert_response :success assert_template 'new' assert_equal 'text/javascript', response.content_type diff --git a/test/functional/groups_controller_test.rb b/test/functional/groups_controller_test.rb index 252472ab6..d1a2b6729 100644 --- a/test/functional/groups_controller_test.rb +++ b/test/functional/groups_controller_test.rb @@ -201,7 +201,7 @@ class GroupsControllerTest < ActionController::TestCase end def test_autocomplete_for_user - get :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js' + xhr :get, :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js' assert_response :success assert_include 'John Smith', response.body end diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 44c43e3b2..6b2dd7110 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -474,12 +474,8 @@ class IssuesControllerTest < ActionController::TestCase def test_index_csv_big_5 with_settings :default_language => "zh-TW" do - 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 + str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8') + str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5') issue = Issue.generate!(:subject => str_utf8) get :index, :project_id => 1, @@ -488,10 +484,7 @@ class IssuesControllerTest < ActionController::TestCase :format => 'csv' assert_equal 'text/csv; header=present', @response.content_type lines = @response.body.chomp.split("\n") - s1 = "\xaa\xac\xbaA" - if str_utf8.respond_to?(:force_encoding) - s1.force_encoding('Big5') - end + s1 = "\xaa\xac\xbaA".force_encoding('Big5') assert_include s1, lines[0] assert_include str_big5, lines[1] end @@ -499,10 +492,7 @@ class IssuesControllerTest < ActionController::TestCase def test_index_csv_cannot_convert_should_be_replaced_big_5 with_settings :default_language => "zh-TW" do - str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" - if str_utf8.respond_to?(:force_encoding) - str_utf8.force_encoding('UTF-8') - end + str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8') issue = Issue.generate!(:subject => str_utf8) get :index, :project_id => 1, @@ -513,21 +503,11 @@ class IssuesControllerTest < ActionController::TestCase :set_filter => 1 assert_equal 'text/csv; header=present', @response.content_type lines = @response.body.chomp.split("\n") - s1 = "\xaa\xac\xbaA" # status - if str_utf8.respond_to?(:force_encoding) - s1.force_encoding('Big5') - end + s1 = "\xaa\xac\xbaA".force_encoding('Big5') # status assert lines[0].include?(s1) s2 = lines[1].split(",")[2] - if s1.respond_to?(:force_encoding) - s3 = "\xa5H?" # subject - s3.force_encoding('Big5') - assert_equal s3, s2 - elsif RUBY_PLATFORM == 'java' - assert_equal "??", s2 - else - assert_equal "\xa5H???", s2 - end + s3 = "\xa5H?".force_encoding('Big5') # subject + assert_equal s3, s2 end end @@ -3120,20 +3100,15 @@ class IssuesControllerTest < ActionController::TestCase def test_put_update_with_attachment_that_fails_to_save set_tmp_attachments_directory - # Delete all fixtured journals, a race condition can occur causing the wrong - # journal to get fetched in the next find. - Journal.delete_all - - # Mock out the unsaved attachment - Attachment.any_instance.stubs(:create).returns(Attachment.new) - # anonymous user - put :update, - :id => 1, - :issue => {:notes => ''}, - :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} - assert_redirected_to :action => 'show', :id => '1' - assert_equal '1 file(s) could not be saved.', flash[:warning] + with_settings :attachment_max_size => 0 do + put :update, + :id => 1, + :issue => {:notes => ''}, + :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} + assert_redirected_to :action => 'show', :id => '1' + assert_equal '1 file(s) could not be saved.', flash[:warning] + end end def test_put_update_with_no_change @@ -3379,7 +3354,7 @@ class IssuesControllerTest < ActionController::TestCase post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} assert_response :success assert_template 'bulk_edit' - assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort + assert_equal Project.find(1).shared_versions.open.to_a.sort, assigns(:versions).sort assert_select 'select[name=?]', 'issue[fixed_version_id]' do assert_select 'option', :text => '2.0' diff --git a/test/functional/issues_custom_fields_visibility_test.rb b/test/functional/issues_custom_fields_visibility_test.rb index cf164665a..afa54c933 100644 --- a/test/functional/issues_custom_fields_visibility_test.rb +++ b/test/functional/issues_custom_fields_visibility_test.rb @@ -199,8 +199,8 @@ class IssuesCustomFieldsVisibilityTest < ActionController::TestCase p1 = Project.generate! p2 = Project.generate! user = User.generate! - User.add_to_project(user, p1, Role.where(:id => [1, 3]).all) - User.add_to_project(user, p2, Role.where(:id => 3).all) + User.add_to_project(user, p1, Role.where(:id => [1, 3]).to_a) + User.add_to_project(user, p2, Role.where(:id => 3).to_a) Issue.generate!(:project => p1, :tracker_id => 1, :custom_field_values => {@field2.id => 'ValueA'}) Issue.generate!(:project => p2, :tracker_id => 1, :custom_field_values => {@field2.id => 'ValueB'}) Issue.generate!(:project => p1, :tracker_id => 1, :custom_field_values => {@field2.id => 'ValueC'}) diff --git a/test/functional/members_controller_test.rb b/test/functional/members_controller_test.rb index 4710916ad..a1ab6f93a 100644 --- a/test/functional/members_controller_test.rb +++ b/test/functional/members_controller_test.rb @@ -104,7 +104,7 @@ class MembersControllerTest < ActionController::TestCase end def test_autocomplete - get :autocomplete, :project_id => 1, :q => 'mis', :format => 'js' + xhr :get, :autocomplete, :project_id => 1, :q => 'mis', :format => 'js' assert_response :success assert_include 'User Misc', response.body end diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb index 075bab96f..8b15d517a 100644 --- a/test/functional/messages_controller_test.rb +++ b/test/functional/messages_controller_test.rb @@ -59,8 +59,8 @@ class MessagesControllerTest < ActionController::TestCase assert_template 'show' replies = assigns(:replies) assert_not_nil replies - assert !replies.include?(message.children.order('id').first) - assert replies.include?(message.children.order('id').last) + assert_not_include message.children.reorder('id').first, replies + assert_include message.children.reorder('id').last, replies end def test_show_with_reply_permission diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb index 53c73341a..b9e965491 100644 --- a/test/functional/my_controller_test.rb +++ b/test/functional/my_controller_test.rb @@ -167,7 +167,7 @@ class MyControllerTest < ActionController::TestCase :new_password_confirmation => 'secret1234' assert_response :success assert_template 'password' - assert_error_tag :content => /Password doesn't match confirmation/ + assert_error_tag :content => /Password doesn.*t match confirmation/ # wrong password post :password, :password => 'wrongpassword', diff --git a/test/functional/repositories_bazaar_controller_test.rb b/test/functional/repositories_bazaar_controller_test.rb index 2321f2ec2..5da8549df 100644 --- a/test/functional/repositories_bazaar_controller_test.rb +++ b/test/functional/repositories_bazaar_controller_test.rb @@ -26,7 +26,7 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk") PRJ_ID = 3 - CHAR_1_UTF8_HEX = "\xc3\x9c" + CHAR_1_UTF8_HEX = "\xc3\x9c".dup.force_encoding('UTF-8') def setup User.current = nil @@ -36,10 +36,6 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase :url => REPOSITORY_PATH_TRUNK, :log_encoding => 'UTF-8') assert @repository - @char_1_utf8 = CHAR_1_UTF8_HEX.dup - if @char_1_utf8.respond_to?(:force_encoding) - @char_1_utf8.force_encoding('UTF-8') - end end if File.directory?(REPOSITORY_PATH) @@ -176,31 +172,29 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase end end - if REPOSITORY_PATH.respond_to?(:force_encoding) - def test_annotate_author_non_ascii - log_encoding = nil - if Encoding.locale_charmap == "UTF-8" || - Encoding.locale_charmap == "ISO-8859-1" - log_encoding = Encoding.locale_charmap - end - unless log_encoding.nil? - repository = Repository::Bazaar.create( - :project => @project, - :url => File.join(REPOSITORY_PATH, "author_non_ascii"), - :identifier => 'author_non_ascii', - :log_encoding => log_encoding) - assert repository - get :annotate, :id => PRJ_ID, :repository_id => 'author_non_ascii', - :path => repository_path_hash(['author-non-ascii-test.txt'])[:param] - assert_response :success - assert_template 'annotate' - assert_select "th.line-num", :text => '1' do - assert_select "+ td.revision" do - assert_select "a", :text => '2' - assert_select "+ td.author", :text => "test #{@char_1_utf8}" do - assert_select "+ td", - :text => "author non ASCII test" - end + def test_annotate_author_non_ascii + log_encoding = nil + if Encoding.locale_charmap == "UTF-8" || + Encoding.locale_charmap == "ISO-8859-1" + log_encoding = Encoding.locale_charmap + end + unless log_encoding.nil? + repository = Repository::Bazaar.create( + :project => @project, + :url => File.join(REPOSITORY_PATH, "author_non_ascii"), + :identifier => 'author_non_ascii', + :log_encoding => log_encoding) + assert repository + get :annotate, :id => PRJ_ID, :repository_id => 'author_non_ascii', + :path => repository_path_hash(['author-non-ascii-test.txt'])[:param] + assert_response :success + assert_template 'annotate' + assert_select "th.line-num", :text => '1' do + assert_select "+ td.revision" do + assert_select "a", :text => '2' + assert_select "+ td.author", :text => "test #{CHAR_1_UTF8_HEX}" do + assert_select "+ td", + :text => "author non ASCII test" end end end diff --git a/test/functional/repositories_filesystem_controller_test.rb b/test/functional/repositories_filesystem_controller_test.rb index 0a1f7da36..ee904d8e5 100644 --- a/test/functional/repositories_filesystem_controller_test.rb +++ b/test/functional/repositories_filesystem_controller_test.rb @@ -27,8 +27,7 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase PRJ_ID = 3 def setup - @ruby19_non_utf8_pass = - (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') + @ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8' User.current = nil Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem') @project = Project.find(PRJ_ID) @@ -94,12 +93,11 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase :attributes => { :class => 'line-num' }, :sibling => { :tag => 'td', :content => /japanese/ } if @ruby19_non_utf8_pass - puts "TODO: show repository file contents test fails in Ruby 1.9 " + - "and Encoding.default_external is not UTF-8. " + + puts "TODO: show repository file contents test fails " + + "when Encoding.default_external is not UTF-8. " + "Current value is '#{Encoding.default_external.to_s}'" else - str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" - str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding) + str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8') assert_tag :tag => 'th', :content => '3', :attributes => { :class => 'line-num' }, @@ -109,7 +107,7 @@ class RepositoriesFilesystemControllerTest < ActionController::TestCase end def test_show_utf16 - enc = (RUBY_VERSION == "1.9.2" ? 'UTF-16LE' : 'UTF-16') + enc = 'UTF-16' with_settings :repositories_encodings => enc do get :entry, :id => PRJ_ID, :path => repository_path_hash(['japanese', 'utf-16.txt'])[:param] diff --git a/test/functional/repositories_git_controller_test.rb b/test/functional/repositories_git_controller_test.rb index 25467e585..e20adeab5 100644 --- a/test/functional/repositories_git_controller_test.rb +++ b/test/functional/repositories_git_controller_test.rb @@ -26,8 +26,8 @@ class RepositoriesGitControllerTest < ActionController::TestCase REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? PRJ_ID = 3 - CHAR_1_HEX = "\xc3\x9c" - FELIX_HEX = "Felix Sch\xC3\xA4fer" + CHAR_1_HEX = "\xc3\x9c".force_encoding('UTF-8') + FELIX_HEX = "Felix Sch\xC3\xA4fer".force_encoding('UTF-8') NUM_REV = 28 ## Git, Mercurial and CVS path encodings are binary. @@ -39,8 +39,7 @@ class RepositoriesGitControllerTest < ActionController::TestCase JRUBY_SKIP_STR = "TODO: This test fails in JRuby" def setup - @ruby19_non_utf8_pass = - (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') + @ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8' User.current = nil @project = Project.find(PRJ_ID) @@ -50,12 +49,6 @@ class RepositoriesGitControllerTest < ActionController::TestCase :path_encoding => 'ISO-8859-1' ) assert @repository - @char_1 = CHAR_1_HEX.dup - @felix_utf8 = FELIX_HEX.dup - if @char_1.respond_to?(:force_encoding) - @char_1.force_encoding('UTF-8') - @felix_utf8.force_encoding('UTF-8') - end end def test_create_and_update @@ -231,7 +224,7 @@ class RepositoriesGitControllerTest < ActionController::TestCase with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| get :entry, :id => PRJ_ID, - :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], + :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param], :rev => r1 assert_response :success assert_template 'entry' @@ -239,7 +232,7 @@ class RepositoriesGitControllerTest < ActionController::TestCase :content => '1', :attributes => { :class => 'line-num' }, :sibling => { :tag => 'td', - :content => /test-#{@char_1}.txt/ } + :content => /test-#{CHAR_1_HEX}.txt/ } end end end @@ -419,14 +412,14 @@ class RepositoriesGitControllerTest < ActionController::TestCase :descendant => { :tag => 'th', :attributes => { :class => 'filename' } , - :content => /latin-1-dir\/test-#{@char_1}.txt/ , + :content => /latin-1-dir\/test-#{CHAR_1_HEX}.txt/ , }, :sibling => { :tag => 'tbody', :descendant => { :tag => 'td', :attributes => { :class => /diff_in/ }, - :content => /test-#{@char_1}.txt/ + :content => /test-#{CHAR_1_HEX}.txt/ } } end @@ -498,11 +491,13 @@ class RepositoriesGitControllerTest < ActionController::TestCase end def test_annotate_binary_file - get :annotate, :id => PRJ_ID, - :path => repository_path_hash(['images', 'edit.png'])[:param] - assert_response 500 - assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, - :content => /cannot be annotated/ + with_settings :default_language => 'en' do + get :annotate, :id => PRJ_ID, + :path => repository_path_hash(['images', 'edit.png'])[:param] + assert_response 500 + assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, + :content => /cannot be annotated/ + end end def test_annotate_error_when_too_big @@ -533,14 +528,14 @@ class RepositoriesGitControllerTest < ActionController::TestCase with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| get :annotate, :id => PRJ_ID, - :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], + :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param], :rev => r1 assert_select "th.line-num", :text => '1' do assert_select "+ td.revision" do assert_select "a", :text => '57ca437c' assert_select "+ td.author", :text => "jsmith" do assert_select "+ td", - :text => "test-#{@char_1}.txt" + :text => "test-#{CHAR_1_HEX}.txt" end end end @@ -557,7 +552,7 @@ class RepositoriesGitControllerTest < ActionController::TestCase assert_select "th.line-num", :text => '1' do assert_select "+ td.revision" do assert_select "a", :text => '83ca5fd5' - assert_select "+ td.author", :text => @felix_utf8 do + assert_select "+ td.author", :text => FELIX_HEX do assert_select "+ td", :text => "And this is a file with a leading and trailing space..." end @@ -643,8 +638,8 @@ class RepositoriesGitControllerTest < ActionController::TestCase private def puts_ruby19_non_utf8_pass - puts "TODO: This test fails in Ruby 1.9 " + - "and Encoding.default_external is not UTF-8. " + + puts "TODO: This test fails " + + "when Encoding.default_external is not UTF-8. " + "Current value is '#{Encoding.default_external.to_s}'" end else diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb index 8eec4f3de..382aa5ccf 100644 --- a/test/functional/repositories_mercurial_controller_test.rb +++ b/test/functional/repositories_mercurial_controller_test.rb @@ -28,8 +28,7 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase PRJ_ID = 3 NUM_REV = 34 - ruby19_non_utf8_pass = - (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') + ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8' def setup User.current = nil @@ -41,21 +40,15 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase ) assert @repository @diff_c_support = true - @char_1 = CHAR_1_HEX.dup - @tag_char_1 = "tag-#{CHAR_1_HEX}-00" - @branch_char_0 = "branch-#{CHAR_1_HEX}-00" - @branch_char_1 = "branch-#{CHAR_1_HEX}-01" - if @char_1.respond_to?(:force_encoding) - @char_1.force_encoding('UTF-8') - @tag_char_1.force_encoding('UTF-8') - @branch_char_0.force_encoding('UTF-8') - @branch_char_1.force_encoding('UTF-8') - end + @char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8') + @tag_char_1 = "tag-#{CHAR_1_HEX}-00".force_encoding('UTF-8') + @branch_char_0 = "branch-#{CHAR_1_HEX}-00".force_encoding('UTF-8') + @branch_char_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8') end if ruby19_non_utf8_pass - puts "TODO: Mercurial functional test fails in Ruby 1.9 " + - "and Encoding.default_external is not UTF-8. " + + puts "TODO: Mercurial functional test fails " + + "when Encoding.default_external is not UTF-8. " + "Current value is '#{Encoding.default_external.to_s}'" def test_fake; assert true end elsif File.directory?(REPOSITORY_PATH) diff --git a/test/functional/roles_controller_test.rb b/test/functional/roles_controller_test.rb index 54509b77c..6e1fc3da5 100644 --- a/test/functional/roles_controller_test.rb +++ b/test/functional/roles_controller_test.rb @@ -31,7 +31,7 @@ class RolesControllerTest < ActionController::TestCase assert_template 'index' assert_not_nil assigns(:roles) - assert_equal Role.order('builtin, position').all, assigns(:roles) + assert_equal Role.order('builtin, position').to_a, assigns(:roles) assert_tag :tag => 'a', :attributes => { :href => '/roles/1/edit' }, :content => 'Manager' @@ -160,7 +160,7 @@ class RolesControllerTest < ActionController::TestCase assert_template 'permissions' assert_not_nil assigns(:roles) - assert_equal Role.order('builtin, position').all, assigns(:roles) + assert_equal Role.order('builtin, position').to_a, assigns(:roles) assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'permissions[3][]', diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 25bd36f15..5b8e1acc4 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -40,7 +40,9 @@ class SearchControllerTest < ActionController::TestCase end def test_search_all_projects - get :index, :q => 'recipe subproject commit', :all_words => '' + with_settings :default_language => 'en' do + get :index, :q => 'recipe subproject commit', :all_words => '' + end assert_response :success assert_template 'index' diff --git a/test/functional/time_entry_reports_controller_test.rb b/test/functional/time_entry_reports_controller_test.rb index bbc4d3c1d..16a477079 100644 --- a/test/functional/time_entry_reports_controller_test.rb +++ b/test/functional/time_entry_reports_controller_test.rb @@ -240,12 +240,8 @@ class TimeEntryReportsControllerTest < ActionController::TestCase 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 + str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8') + str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5') user = User.find_by_id(3) user.firstname = str_utf8 user.lastname = "test-lastname" @@ -270,21 +266,14 @@ class TimeEntryReportsControllerTest < ActionController::TestCase assert_equal 'text/csv; header=present', @response.content_type lines = @response.body.chomp.split("\n") # Headers - s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp" - s2 = "\xa4u\xae\xc9\xc1`\xadp" - if s1.respond_to?(:force_encoding) - s1.force_encoding('Big5') - s2.force_encoding('Big5') - end + s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5') + s2 = "\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5') assert_equal s1, lines.first # Total row assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1] assert_equal "#{s2},7.30,7.30", lines[2] - 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 + str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)".force_encoding('UTF-8') assert_equal str_tw, l(:general_lang_name) assert_equal 'Big5', l(:general_csv_encoding) assert_equal ',', l(:general_csv_separator) @@ -293,10 +282,7 @@ class TimeEntryReportsControllerTest < ActionController::TestCase 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 + str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8') user = User.find_by_id(3) user.firstname = str_utf8 user.lastname = "test-lastname" @@ -321,21 +307,10 @@ class TimeEntryReportsControllerTest < ActionController::TestCase assert_equal 'text/csv; header=present', @response.content_type lines = @response.body.chomp.split("\n") # Headers - s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp" - if s1.respond_to?(:force_encoding) - s1.force_encoding('Big5') - end + s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5') 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 + s2 = "\xa5H?".force_encoding('Big5') assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1] end @@ -362,21 +337,14 @@ class TimeEntryReportsControllerTest < ActionController::TestCase assert_equal 'text/csv; header=present', @response.content_type lines = @response.body.chomp.split("\n") # Headers - s1 = "Utilisateur;2011-11-11;Temps total" - s2 = "Temps total" - if s1.respond_to?(:force_encoding) - s1.force_encoding('ISO-8859-1') - s2.force_encoding('ISO-8859-1') - end + s1 = "Utilisateur;2011-11-11;Temps total".force_encoding('ISO-8859-1') + s2 = "Temps total".force_encoding('ISO-8859-1') 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 + str_fr = "Fran\xc3\xa7ais".force_encoding('UTF-8') assert_equal str_fr, l(:general_lang_name) assert_equal 'ISO-8859-1', l(:general_csv_encoding) assert_equal ';', l(:general_csv_separator) diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index cc76cba21..72a45f81b 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -702,16 +702,18 @@ class TimelogControllerTest < ActionController::TestCase end 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 + with_settings :date_format => '%m/%d/%Y' do + get :index, :format => 'csv' + assert_response :success + assert_equal 'text/csv; header=present', response.content_type + end end 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 + with_settings :date_format => '%m/%d/%Y' do + get :index, :project_id => 1, :format => 'csv' + assert_response :success + assert_equal 'text/csv; header=present', response.content_type + end end end diff --git a/test/functional/timelog_custom_fields_visibility_test.rb b/test/functional/timelog_custom_fields_visibility_test.rb index 8f474c1d6..a5648de78 100644 --- a/test/functional/timelog_custom_fields_visibility_test.rb +++ b/test/functional/timelog_custom_fields_visibility_test.rb @@ -95,8 +95,8 @@ class TimelogCustomFieldsVisibilityTest < ActionController::TestCase p1 = Project.generate! p2 = Project.generate! user = User.generate! - User.add_to_project(user, p1, Role.where(:id => [1, 3]).all) - User.add_to_project(user, p2, Role.where(:id => 3).all) + User.add_to_project(user, p1, Role.where(:id => [1, 3]).to_a) + User.add_to_project(user, p2, Role.where(:id => 3).to_a) TimeEntry.generate!( :issue => Issue.generate!(:project => p1, :tracker_id => 1, :custom_field_values => {@field2.id => 'ValueA'})) @@ -108,9 +108,9 @@ class TimelogCustomFieldsVisibilityTest < ActionController::TestCase :custom_field_values => {@field2.id => 'ValueC'})) @request.session[:user_id] = user.id get :index, :c => ["hours", "issue.cf_#{@field2.id}"] - assert_select 'td', :text => 'ValueA' + assert_select 'td', {:text => 'ValueA'}, "ValueA not found in:\n#{response.body}" assert_select 'td', :text => 'ValueB', :count => 0 - assert_select 'td', :text => 'ValueC' + assert_select 'td', {:text => 'ValueC'}, "ValueC not found in:\n#{response.body}" get :index, :set_filter => '1', "issue.cf_#{@field2.id}" => '*' assert_equal %w(ValueA ValueC), assigns(:entries).map{|i| i.issue.custom_field_value(@field2)}.sort diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb index 350918359..aa9afaeaf 100644 --- a/test/functional/welcome_controller_test.rb +++ b/test/functional/welcome_controller_test.rb @@ -97,9 +97,7 @@ class WelcomeControllerTest < ActionController::TestCase @request.session[:user_id] = 2 get :index - assert_tag 'script', - :attributes => {:type => "text/javascript"}, - :content => %r{warnLeavingUnsaved} + assert_select 'script', :text => %r{warnLeavingUnsaved} end def test_warn_on_leaving_unsaved_turn_off diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 3e25be08e..41f5dabdb 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -58,7 +58,9 @@ class WikiControllerTest < ActionController::TestCase end def test_show_old_version - get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2' + with_settings :default_language => 'en' do + get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '2' + end assert_response :success assert_template 'show' @@ -89,7 +91,9 @@ class WikiControllerTest < ActionController::TestCase end def test_show_first_version - get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1' + with_settings :default_language => 'en' do + get :show, :project_id => 'ecookbook', :id => 'CookBook_documentation', :version => '1' + end assert_response :success assert_template 'show' diff --git a/test/functional/workflows_controller_test.rb b/test/functional/workflows_controller_test.rb index ea00cbc77..5885c4e20 100644 --- a/test/functional/workflows_controller_test.rb +++ b/test/functional/workflows_controller_test.rb @@ -248,7 +248,7 @@ class WorkflowsControllerTest < ActionController::TestCase get :permissions, :role_id => 1, :tracker_id => 2, :used_statuses_only => '0' assert_response :success - assert_equal IssueStatus.sorted.all, assigns(:statuses) + assert_equal IssueStatus.sorted.to_a, assigns(:statuses) end def test_post_permissions |