From 10fdd1fee7a6a9afb734406c64ff0fea9f29f24d Mon Sep 17 00:00:00 2001 From: Alexander Meindl Date: Sun, 15 Jul 2018 19:08:39 +0200 Subject: [PATCH] More test fixed for redmine 4 --- test/controllers | 1 - test/functional/account_controller_test.rb | 30 +++--- test/functional/issues_controller_test.rb | 55 +++++----- test/functional/projects_controller_test.rb | 26 ++--- test/functional/users_controller_test.rb | 22 ++-- test/functional/welcome_controller_test.rb | 66 ++++++------ test/functional/wiki_controller_test.rb | 48 ++++----- test/integration/api_test/issues_test.rb | 86 +++++++-------- test/test_helper.rb | 5 +- test/unit/issue_test.rb | 20 ++-- test/unit/watcher_test.rb | 110 +++++++++++--------- 11 files changed, 247 insertions(+), 222 deletions(-) delete mode 120000 test/controllers diff --git a/test/controllers b/test/controllers deleted file mode 120000 index 2a52a53b..00000000 --- a/test/controllers +++ /dev/null @@ -1 +0,0 @@ -functional \ No newline at end of file diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 1c4cf839..a0894b93 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -9,25 +9,23 @@ class AccountControllerTest < Additionals::ControllerTest end def test_get_login_with_welcome_text - with_additionals_settings(account_login_bottom: 'Lore impsuum') - - get :login - assert_response :success - - assert_select 'input[name=username]' - assert_select 'input[name=password]' - assert_select 'div.login-additionals', text: /Lore impsuum/ + with_additionals_settings(account_login_bottom: 'Lore impsuum') do + get :login + assert_response :success + assert_select 'input[name=username]' + assert_select 'input[name=password]' + assert_select 'div.login-additionals', text: /Lore impsuum/ + end end def test_get_login_without_welcome_text - with_additionals_settings(account_login_bottom: '') - - get :login - assert_response :success - - assert_select 'input[name=username]' - assert_select 'input[name=password]' - assert_select 'div.login-additionals', count: 0 + with_additionals_settings(account_login_bottom: '') do + get :login + assert_response :success + assert_select 'input[name=username]' + assert_select 'input[name=password]' + assert_select 'div.login-additionals', count: 0 + end end # See integration/account_test.rb for the full test diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index f1fbe450..6a8cab7a 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -86,42 +86,47 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'show assign-to-me on issue' do - with_additionals_settings(issue_assign_to_me: 1) - @request.session[:user_id] = 2 - get :show, - params: { id: 2 } - assert_select 'a.assign-to-me' + with_additionals_settings(issue_assign_to_me: 1) do + @request.session[:user_id] = 2 + get :show, + params: { id: 2 } + assert_select 'a.assign-to-me' + end end test 'don\'t show assign-to-me on issue without activation' do - with_additionals_settings(issue_assign_to_me: 0) - @request.session[:user_id] = 2 - get :show, - params: { id: 2 } - assert_select 'a.assign-to-me', count: 0 + with_additionals_settings(issue_assign_to_me: 0) do + @request.session[:user_id] = 2 + get :show, + params: { id: 2 } + assert_select 'a.assign-to-me', count: 0 + end end test 'don\'t show assign-to-me on issue with already assigned_to me' do - with_additionals_settings(issue_assign_to_me: 1) - @request.session[:user_id] = 2 - get :show, - params: { id: 4 } - assert_select 'a.assign-to-me', count: 0 + with_additionals_settings(issue_assign_to_me: 1) do + @request.session[:user_id] = 2 + get :show, + params: { id: 4 } + assert_select 'a.assign-to-me', count: 0 + end end test 'show change status in issue sidebar' do - with_additionals_settings(issue_change_status_in_sidebar: 1) - @request.session[:user_id] = 2 - get :show, - params: { id: 2 } - assert_select 'ul.issue-status-change-sidebar' + with_additionals_settings(issue_change_status_in_sidebar: 1) do + @request.session[:user_id] = 2 + get :show, + params: { id: 2 } + assert_select 'ul.issue-status-change-sidebar' + end end test 'don\'t show change status in issue sidebar without activation' do - with_additionals_settings(issue_change_status_in_sidebar: 0) - @request.session[:user_id] = 2 - get :show, - params: { id: 2 } - assert_select 'ul.issue-status-change-sidebar', count: 0 + with_additionals_settings(issue_change_status_in_sidebar: 0) do + @request.session[:user_id] = 2 + get :show, + params: { id: 2 } + assert_select 'ul.issue-status-change-sidebar', count: 0 + end end end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index e9eb98fe..0ea103a4 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -20,22 +20,24 @@ class ProjectsControllerTest < Additionals::ControllerTest end def test_show_overview_content - with_additionals_settings(project_overview_content: 'Lore impsuum') - @request.session[:user_id] = 4 - get :show, - params: { id: 1 } + with_additionals_settings(project_overview_content: 'Lore impsuum') do + @request.session[:user_id] = 4 + get :show, + params: { id: 1 } - assert_response :success - assert_select 'div.project-content', text: /Lore impsuum/ + assert_response :success + assert_select 'div.project-content', text: /Lore impsuum/ + end end def test_do_not_show_overview_content_box - with_additionals_settings(project_overview_content: '') - @request.session[:user_id] = 4 - get :show, - params: { id: 1 } + with_additionals_settings(project_overview_content: '') do + @request.session[:user_id] = 4 + get :show, + params: { id: 1 } - assert_response :success - assert_select 'div.project-content', count: 0 + assert_response :success + assert_select 'div.project-content', count: 0 + end end end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 018703c1..e248bfc6 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -23,18 +23,20 @@ class UsersControllerTest < Additionals::ControllerTest end def test_show_new_issue_on_profile - with_additionals_settings(new_issue_on_profile: 1) - @request.session[:user_id] = 2 - get :show, - params: { id: 2 } - assert_select 'a.user-new-issue' + with_additionals_settings(new_issue_on_profile: 1) do + @request.session[:user_id] = 2 + get :show, + params: { id: 2 } + assert_select 'a.user-new-issue' + end end def test_not_show_new_issue_on_profile_without_activated - with_additionals_settings(new_issue_on_profile: 0) - @request.session[:user_id] = 2 - get :show, - params: { id: 2 } - assert_select 'a.user-new-issue', count: 0 + with_additionals_settings(new_issue_on_profile: 0) do + @request.session[:user_id] = 2 + get :show, + params: { id: 2 } + assert_select 'a.user-new-issue', count: 0 + end end end diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb index a5702096..37a97b6a 100644 --- a/test/functional/welcome_controller_test.rb +++ b/test/functional/welcome_controller_test.rb @@ -9,56 +9,62 @@ class WelcomeControllerTest < Additionals::ControllerTest end def test_show_with_overview_right - with_additionals_settings(overview_right: 'Lore impsuum') - @request.session[:user_id] = 4 - get :index + with_additionals_settings(overview_right: 'Lore impsuum') do + @request.session[:user_id] = 4 + get :index - assert_response :success - assert_select 'div.overview-right', text: /Lore impsuum/ + assert_response :success + assert_select 'div.overview-right', text: /Lore impsuum/ + end end def test_show_without_overview_right - with_additionals_settings(overview_right: '') - @request.session[:user_id] = 4 - get :index + with_additionals_settings(overview_right: '') do + @request.session[:user_id] = 4 + get :index - assert_response :success - assert_select 'div.overview-right', count: 0 + assert_response :success + assert_select 'div.overview-right', count: 0 + end end def test_show_with_overview_bottom - with_additionals_settings(overview_bottom: 'Lore impsuum') - @request.session[:user_id] = 4 - get :index + with_additionals_settings(overview_bottom: 'Lore impsuum') do + @request.session[:user_id] = 4 + get :index - assert_response :success - assert_select 'div.overview-bottom', text: /Lore impsuum/ + assert_response :success + assert_select 'div.overview-bottom', text: /Lore impsuum/ + end end def test_show_without_overview_bottom - with_additionals_settings(overview_bottom: '') - @request.session[:user_id] = 4 - get :index + with_additionals_settings(overview_bottom: '') do + @request.session[:user_id] = 4 + get :index - assert_response :success - assert_select 'div.overview-bottom', count: 0 + assert_response :success + assert_select 'div.overview-bottom', count: 0 + end end def test_show_with_overview_top - with_additionals_settings(overview_top: 'Lore impsuum') - @request.session[:user_id] = 4 - get :index + with_additionals_settings(overview_top: 'Lore impsuum') do + @request.session[:user_id] = 4 + get :index - assert_response :success - assert_select 'div.overview-top', text: /Lore impsuum/ + assert_response :success + assert_select 'div.overview-top', text: /Lore impsuum/ + end end def test_show_without_overview_top - with_additionals_settings(overview_top: '') - @request.session[:user_id] = 4 - get :index + with_additionals_settings(overview_top: '') do + @request.session[:user_id] = 4 + get :index - assert_response :success - assert_select 'div.overview-top', count: 0 + assert_response :success + assert_select 'div.overview-top', count: 0 + end end end diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index ee044109..c6e42922 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -368,42 +368,42 @@ class WikiControllerTest < Additionals::ControllerTest end def test_show_wiki_with_header - with_additionals_settings(global_wiki_header: 'Lore impsuum') + with_additionals_settings(global_wiki_header: 'Lore impsuum') do + get :show, + params: { project_id: 1, id: 'Another_page' } - get :show, - params: { project_id: 1, id: 'Another_page' } - - assert_response :success - assert_select 'div#wiki_extentions_header', text: /Lore impsuum/ + assert_response :success + assert_select 'div#wiki_extentions_header', text: /Lore impsuum/ + end end def test_show_wiki_without_header - with_additionals_settings(global_wiki_header: '') + with_additionals_settings(global_wiki_header: '') do + get :show, + params: { project_id: 1, id: 'Another_page' } - get :show, - params: { project_id: 1, id: 'Another_page' } - - assert_response :success - assert_select 'div#wiki_extentions_header', count: 0 + assert_response :success + assert_select 'div#wiki_extentions_header', count: 0 + end end def test_show_wiki_with_footer - with_additionals_settings(global_wiki_footer: 'Lore impsuum') + with_additionals_settings(global_wiki_footer: 'Lore impsuum') do + get :show, + params: { project_id: 1, id: 'Another_page' } - get :show, - params: { project_id: 1, id: 'Another_page' } - - assert_response :success - assert_select 'div#wiki_extentions_footer', text: /Lore impsuum/ + assert_response :success + assert_select 'div#wiki_extentions_footer', text: /Lore impsuum/ + end end def test_show_wiki_without_footer - with_additionals_settings(global_wiki_footer: '') + with_additionals_settings(global_wiki_footer: '') do + get :show, + params: { project_id: 1, id: 'Another_page' } - get :show, - params: { project_id: 1, id: 'Another_page' } - - assert_response :success - assert_select 'div#wiki_extentions_footer', count: 0 + assert_response :success + assert_select 'div#wiki_extentions_footer', count: 0 + end end end diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb index 2e144848..6d1a3bb8 100644 --- a/test/integration/api_test/issues_test.rb +++ b/test/integration/api_test/issues_test.rb @@ -42,61 +42,61 @@ module ApiTest with_additionals_settings(issue_status_change: '0', issue_auto_assign: '0', issue_auto_assign_status: ['1'], - issue_auto_assign_role: '1') + issue_auto_assign_role: '1') do + payload = <<-XML + + + 1 + 2 + 3 + API test + + XML - payload = <<-XML - - - 1 - 2 - 3 - API test - - XML + assert_difference('Issue.count') do + post '/issues.xml', + params: payload, + headers: { 'CONTENT_TYPE' => 'application/xml' }.merge(credentials('jsmith')) + end + issue = Issue.order(id: :desc).first + assert_equal 1, issue.project_id + assert_nil issue.assigned_to_id + assert_equal 'API test', issue.subject - assert_difference('Issue.count') do - post '/issues.xml', - params: payload, - headers: { 'CONTENT_TYPE' => 'application/xml' }.merge(credentials('jsmith')) + assert_response :created + assert_equal 'application/xml', @response.content_type + assert_select 'issue > id', text: issue.id.to_s end - issue = Issue.order(id: :desc).first - assert_equal 1, issue.project_id - assert_nil issue.assigned_to_id - assert_equal 'API test', issue.subject - - assert_response :created - assert_equal 'application/xml', @response.content_type - assert_select 'issue > id', text: issue.id.to_s end test 'POST /issues.xml should create an issue with auto assigned_to_id' do with_additionals_settings(issue_status_change: '0', issue_auto_assign: '1', issue_auto_assign_status: ['1'], - issue_auto_assign_role: '1') + issue_auto_assign_role: '1') do + payload = <<-XML + + + 1 + API test + + XML - payload = <<-XML - - - 1 - API test - - XML + assert_difference('Issue.count') do + post '/issues.xml', + params: payload, + headers: { 'CONTENT_TYPE' => 'application/xml' }.merge(credentials('jsmith')) + end - assert_difference('Issue.count') do - post '/issues.xml', - params: payload, - headers: { 'CONTENT_TYPE' => 'application/xml' }.merge(credentials('jsmith')) + issue = Issue.order(id: :desc).first + assert_equal 1, issue.project_id + assert_equal 2, issue.assigned_to_id + assert_equal 'API test', issue.subject + + assert_response :created + assert_equal 'application/xml', @response.content_type + assert_select 'issue > id', text: issue.id.to_s end - - issue = Issue.order(id: :desc).first - assert_equal 1, issue.project_id - assert_equal 2, issue.assigned_to_id - assert_equal 'API test', issue.subject - - assert_response :created - assert_equal 'application/xml', @response.content_type - assert_select 'issue > id', text: issue.id.to_s end test 'DELETE /issues/:id.xml' do diff --git a/test/test_helper.rb b/test/test_helper.rb index 44ab194b..b7dd196d 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,8 +17,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') module Additionals module TestHelper - def with_additionals_settings(settings) + def with_additionals_settings(settings, &_block) Additionals.change_settings = settings + yield + ensure + Additionals.change_settings = Setting[:plugin_additionals] end end diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 6cec4a40..8ae03001 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -67,21 +67,21 @@ class IssueTest < ActiveSupport::TestCase with_additionals_settings(issue_status_change: '0', issue_auto_assign: '1', issue_auto_assign_status: ['1'], - issue_auto_assign_role: '1') - - issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') - assert issue.save - assert_equal 2, issue.assigned_to_id + issue_auto_assign_role: '1') do + issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') + assert issue.save + assert_equal 2, issue.assigned_to_id + end end def test_disabled_auto_assigned_to with_additionals_settings(issue_status_change: '0', issue_auto_assign: '0', issue_auto_assign_status: ['1'], - issue_auto_assign_role: '1') - - issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') - assert issue.save - assert_nil issue.assigned_to_id + issue_auto_assign_role: '1') do + issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') + assert issue.save + assert_nil issue.assigned_to_id + end end end diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index be3c070d..6749035b 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -11,83 +11,93 @@ class WatcherTest < ActiveSupport::TestCase @author = User.find(1) @assigned_user = User.find(2) @changing_user = User.find(4) - with_additionals_settings(issue_autowatch_involved: 1) end def test_new_issue_with_no_autowatch - with_additionals_settings(issue_autowatch_involved: 0) - User.current = @author - issue = Issue.generate(author_id: @author.id) - issue.save - assert_equal 0, issue.watchers.count - assert_not issue.watched_by?(@author) + with_additionals_settings(issue_autowatch_involved: 0) do + User.current = @author + issue = Issue.generate(author_id: @author.id) + issue.save + assert_equal 0, issue.watchers.count + assert_not issue.watched_by?(@author) + end end def test_new_issue_with_no_autowatch_by_user - User.current = @author - User.current.pref.update_attribute :autowatch_involved_issue, false + with_additionals_settings(issue_autowatch_involved: 1) do + User.current = @author + User.current.pref.update_attribute :autowatch_involved_issue, false - issue = Issue.generate(author_id: @author.id) - issue.save - assert_equal 0, issue.watchers.count - assert_not issue.watched_by?(@author) + issue = Issue.generate(author_id: @author.id) + issue.save + assert_equal 0, issue.watchers.count + assert_not issue.watched_by?(@author) + end end def test_new_issue_with_author_watch_only - User.current = @author - issue = Issue.generate(author_id: @author.id) - issue.save - assert_equal 1, issue.watchers.count - assert issue.watched_by?(@author) + with_additionals_settings(issue_autowatch_involved: 1) do + User.current = @author + issue = Issue.generate(author_id: @author.id) + issue.save + assert_equal 1, issue.watchers.count + assert issue.watched_by?(@author) + end end def test_new_issue_with_author_and_assigned_to_watchers - User.current = @author - issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) - issue.save + with_additionals_settings(issue_autowatch_involved: 1) do + User.current = @author + issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) + issue.save - assert_equal 2, issue.watchers.count - assert issue.watched_by?(@author) - assert issue.watched_by?(@assigned_user) + assert_equal 2, issue.watchers.count + assert issue.watched_by?(@author) + assert issue.watched_by?(@assigned_user) + end end def test_issue_do_not_add_author_with_user_change - User.current = @author + with_additionals_settings(issue_autowatch_involved: 1) do + User.current = @author - issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) - issue.save - assert_equal 2, issue.watchers.count + issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) + issue.save + assert_equal 2, issue.watchers.count - issue.remove_watcher(@author) - issue.reload - assert_equal 1, issue.watchers.count + issue.remove_watcher(@author) + issue.reload + assert_equal 1, issue.watchers.count - User.current = @changing_user - issue.subject = 'Changing....' - issue.save + User.current = @changing_user + issue.subject = 'Changing....' + issue.save - assert_equal 2, issue.watchers.count - assert issue.watched_by?(@changing_user) - assert issue.watched_by?(@assigned_user) + assert_equal 2, issue.watchers.count + assert issue.watched_by?(@changing_user) + assert issue.watched_by?(@assigned_user) + end end def test_issue_do_not_add_assigned_to_with_user_change - User.current = @author + with_additionals_settings(issue_autowatch_involved: 1) do + User.current = @author - issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) - issue.save - assert_equal 2, issue.watchers.count + issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) + issue.save + assert_equal 2, issue.watchers.count - issue.remove_watcher(@assigned_user) - issue.reload - assert_equal 1, issue.watchers.count + issue.remove_watcher(@assigned_user) + issue.reload + assert_equal 1, issue.watchers.count - User.current = @changing_user - issue.subject = 'Changing....' - issue.save + User.current = @changing_user + issue.subject = 'Changing....' + issue.save - assert_equal 2, issue.watchers.count - assert issue.watched_by?(@author) - assert issue.watched_by?(@changing_user) + assert_equal 2, issue.watchers.count + assert issue.watched_by?(@author) + assert issue.watched_by?(@changing_user) + end end end