More test fixed for redmine 4

This commit is contained in:
Alexander Meindl
2018-07-15 19:08:39 +02:00
parent 3421763669
commit 10fdd1fee7
11 changed files with 247 additions and 222 deletions

View File

@@ -1 +0,0 @@
functional

View File

@@ -9,26 +9,24 @@ class AccountControllerTest < Additionals::ControllerTest
end end
def test_get_login_with_welcome_text def test_get_login_with_welcome_text
with_additionals_settings(account_login_bottom: 'Lore impsuum') with_additionals_settings(account_login_bottom: 'Lore impsuum') do
get :login get :login
assert_response :success assert_response :success
assert_select 'input[name=username]' assert_select 'input[name=username]'
assert_select 'input[name=password]' assert_select 'input[name=password]'
assert_select 'div.login-additionals', text: /Lore impsuum/ assert_select 'div.login-additionals', text: /Lore impsuum/
end end
end
def test_get_login_without_welcome_text def test_get_login_without_welcome_text
with_additionals_settings(account_login_bottom: '') with_additionals_settings(account_login_bottom: '') do
get :login get :login
assert_response :success assert_response :success
assert_select 'input[name=username]' assert_select 'input[name=username]'
assert_select 'input[name=password]' assert_select 'input[name=password]'
assert_select 'div.login-additionals', count: 0 assert_select 'div.login-additionals', count: 0
end end
end
# See integration/account_test.rb for the full test # See integration/account_test.rb for the full test
def test_post_register_with_registration_on def test_post_register_with_registration_on

View File

@@ -86,42 +86,47 @@ class IssuesControllerTest < Additionals::ControllerTest
end end
test 'show assign-to-me on issue' do test 'show assign-to-me on issue' do
with_additionals_settings(issue_assign_to_me: 1) with_additionals_settings(issue_assign_to_me: 1) do
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, get :show,
params: { id: 2 } params: { id: 2 }
assert_select 'a.assign-to-me' assert_select 'a.assign-to-me'
end end
end
test 'don\'t show assign-to-me on issue without activation' do test 'don\'t show assign-to-me on issue without activation' do
with_additionals_settings(issue_assign_to_me: 0) with_additionals_settings(issue_assign_to_me: 0) do
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, get :show,
params: { id: 2 } params: { id: 2 }
assert_select 'a.assign-to-me', count: 0 assert_select 'a.assign-to-me', count: 0
end end
end
test 'don\'t show assign-to-me on issue with already assigned_to me' do test 'don\'t show assign-to-me on issue with already assigned_to me' do
with_additionals_settings(issue_assign_to_me: 1) with_additionals_settings(issue_assign_to_me: 1) do
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, get :show,
params: { id: 4 } params: { id: 4 }
assert_select 'a.assign-to-me', count: 0 assert_select 'a.assign-to-me', count: 0
end end
end
test 'show change status in issue sidebar' do test 'show change status in issue sidebar' do
with_additionals_settings(issue_change_status_in_sidebar: 1) with_additionals_settings(issue_change_status_in_sidebar: 1) do
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, get :show,
params: { id: 2 } params: { id: 2 }
assert_select 'ul.issue-status-change-sidebar' assert_select 'ul.issue-status-change-sidebar'
end end
end
test 'don\'t show change status in issue sidebar without activation' do test 'don\'t show change status in issue sidebar without activation' do
with_additionals_settings(issue_change_status_in_sidebar: 0) with_additionals_settings(issue_change_status_in_sidebar: 0) do
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, get :show,
params: { id: 2 } params: { id: 2 }
assert_select 'ul.issue-status-change-sidebar', count: 0 assert_select 'ul.issue-status-change-sidebar', count: 0
end end
end
end end

View File

@@ -20,7 +20,7 @@ class ProjectsControllerTest < Additionals::ControllerTest
end end
def test_show_overview_content def test_show_overview_content
with_additionals_settings(project_overview_content: 'Lore impsuum') with_additionals_settings(project_overview_content: 'Lore impsuum') do
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :show, get :show,
params: { id: 1 } params: { id: 1 }
@@ -28,9 +28,10 @@ class ProjectsControllerTest < Additionals::ControllerTest
assert_response :success assert_response :success
assert_select 'div.project-content', text: /Lore impsuum/ assert_select 'div.project-content', text: /Lore impsuum/
end end
end
def test_do_not_show_overview_content_box def test_do_not_show_overview_content_box
with_additionals_settings(project_overview_content: '') with_additionals_settings(project_overview_content: '') do
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :show, get :show,
params: { id: 1 } params: { id: 1 }
@@ -38,4 +39,5 @@ class ProjectsControllerTest < Additionals::ControllerTest
assert_response :success assert_response :success
assert_select 'div.project-content', count: 0 assert_select 'div.project-content', count: 0
end end
end
end end

View File

@@ -23,18 +23,20 @@ class UsersControllerTest < Additionals::ControllerTest
end end
def test_show_new_issue_on_profile def test_show_new_issue_on_profile
with_additionals_settings(new_issue_on_profile: 1) with_additionals_settings(new_issue_on_profile: 1) do
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, get :show,
params: { id: 2 } params: { id: 2 }
assert_select 'a.user-new-issue' assert_select 'a.user-new-issue'
end end
end
def test_not_show_new_issue_on_profile_without_activated def test_not_show_new_issue_on_profile_without_activated
with_additionals_settings(new_issue_on_profile: 0) with_additionals_settings(new_issue_on_profile: 0) do
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :show, get :show,
params: { id: 2 } params: { id: 2 }
assert_select 'a.user-new-issue', count: 0 assert_select 'a.user-new-issue', count: 0
end end
end
end end

View File

@@ -9,56 +9,62 @@ class WelcomeControllerTest < Additionals::ControllerTest
end end
def test_show_with_overview_right def test_show_with_overview_right
with_additionals_settings(overview_right: 'Lore impsuum') with_additionals_settings(overview_right: 'Lore impsuum') do
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :index get :index
assert_response :success assert_response :success
assert_select 'div.overview-right', text: /Lore impsuum/ assert_select 'div.overview-right', text: /Lore impsuum/
end end
end
def test_show_without_overview_right def test_show_without_overview_right
with_additionals_settings(overview_right: '') with_additionals_settings(overview_right: '') do
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :index get :index
assert_response :success assert_response :success
assert_select 'div.overview-right', count: 0 assert_select 'div.overview-right', count: 0
end end
end
def test_show_with_overview_bottom def test_show_with_overview_bottom
with_additionals_settings(overview_bottom: 'Lore impsuum') with_additionals_settings(overview_bottom: 'Lore impsuum') do
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :index get :index
assert_response :success assert_response :success
assert_select 'div.overview-bottom', text: /Lore impsuum/ assert_select 'div.overview-bottom', text: /Lore impsuum/
end end
end
def test_show_without_overview_bottom def test_show_without_overview_bottom
with_additionals_settings(overview_bottom: '') with_additionals_settings(overview_bottom: '') do
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :index get :index
assert_response :success assert_response :success
assert_select 'div.overview-bottom', count: 0 assert_select 'div.overview-bottom', count: 0
end end
end
def test_show_with_overview_top def test_show_with_overview_top
with_additionals_settings(overview_top: 'Lore impsuum') with_additionals_settings(overview_top: 'Lore impsuum') do
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :index get :index
assert_response :success assert_response :success
assert_select 'div.overview-top', text: /Lore impsuum/ assert_select 'div.overview-top', text: /Lore impsuum/
end end
end
def test_show_without_overview_top def test_show_without_overview_top
with_additionals_settings(overview_top: '') with_additionals_settings(overview_top: '') do
@request.session[:user_id] = 4 @request.session[:user_id] = 4
get :index get :index
assert_response :success assert_response :success
assert_select 'div.overview-top', count: 0 assert_select 'div.overview-top', count: 0
end end
end
end end

View File

@@ -368,42 +368,42 @@ class WikiControllerTest < Additionals::ControllerTest
end end
def test_show_wiki_with_header 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, get :show,
params: { project_id: 1, id: 'Another_page' } params: { project_id: 1, id: 'Another_page' }
assert_response :success assert_response :success
assert_select 'div#wiki_extentions_header', text: /Lore impsuum/ assert_select 'div#wiki_extentions_header', text: /Lore impsuum/
end end
end
def test_show_wiki_without_header def test_show_wiki_without_header
with_additionals_settings(global_wiki_header: '') with_additionals_settings(global_wiki_header: '') do
get :show, get :show,
params: { project_id: 1, id: 'Another_page' } params: { project_id: 1, id: 'Another_page' }
assert_response :success assert_response :success
assert_select 'div#wiki_extentions_header', count: 0 assert_select 'div#wiki_extentions_header', count: 0
end end
end
def test_show_wiki_with_footer 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, get :show,
params: { project_id: 1, id: 'Another_page' } params: { project_id: 1, id: 'Another_page' }
assert_response :success assert_response :success
assert_select 'div#wiki_extentions_footer', text: /Lore impsuum/ assert_select 'div#wiki_extentions_footer', text: /Lore impsuum/
end end
end
def test_show_wiki_without_footer def test_show_wiki_without_footer
with_additionals_settings(global_wiki_footer: '') with_additionals_settings(global_wiki_footer: '') do
get :show, get :show,
params: { project_id: 1, id: 'Another_page' } params: { project_id: 1, id: 'Another_page' }
assert_response :success assert_response :success
assert_select 'div#wiki_extentions_footer', count: 0 assert_select 'div#wiki_extentions_footer', count: 0
end end
end
end end

View File

@@ -42,8 +42,7 @@ module ApiTest
with_additionals_settings(issue_status_change: '0', with_additionals_settings(issue_status_change: '0',
issue_auto_assign: '0', issue_auto_assign: '0',
issue_auto_assign_status: ['1'], issue_auto_assign_status: ['1'],
issue_auto_assign_role: '1') issue_auto_assign_role: '1') do
payload = <<-XML payload = <<-XML
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<issue> <issue>
@@ -68,13 +67,13 @@ module ApiTest
assert_equal 'application/xml', @response.content_type assert_equal 'application/xml', @response.content_type
assert_select 'issue > id', text: issue.id.to_s assert_select 'issue > id', text: issue.id.to_s
end end
end
test 'POST /issues.xml should create an issue with auto assigned_to_id' do test 'POST /issues.xml should create an issue with auto assigned_to_id' do
with_additionals_settings(issue_status_change: '0', with_additionals_settings(issue_status_change: '0',
issue_auto_assign: '1', issue_auto_assign: '1',
issue_auto_assign_status: ['1'], issue_auto_assign_status: ['1'],
issue_auto_assign_role: '1') issue_auto_assign_role: '1') do
payload = <<-XML payload = <<-XML
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<issue> <issue>
@@ -98,6 +97,7 @@ module ApiTest
assert_equal 'application/xml', @response.content_type assert_equal 'application/xml', @response.content_type
assert_select 'issue > id', text: issue.id.to_s assert_select 'issue > id', text: issue.id.to_s
end end
end
test 'DELETE /issues/:id.xml' do test 'DELETE /issues/:id.xml' do
assert_difference('Issue.count', -1) do assert_difference('Issue.count', -1) do

View File

@@ -17,8 +17,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')
module Additionals module Additionals
module TestHelper module TestHelper
def with_additionals_settings(settings) def with_additionals_settings(settings, &_block)
Additionals.change_settings = settings Additionals.change_settings = settings
yield
ensure
Additionals.change_settings = Setting[:plugin_additionals]
end end
end end

View File

@@ -67,21 +67,21 @@ class IssueTest < ActiveSupport::TestCase
with_additionals_settings(issue_status_change: '0', with_additionals_settings(issue_status_change: '0',
issue_auto_assign: '1', issue_auto_assign: '1',
issue_auto_assign_status: ['1'], issue_auto_assign_status: ['1'],
issue_auto_assign_role: '1') issue_auto_assign_role: '1') do
issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create')
assert issue.save assert issue.save
assert_equal 2, issue.assigned_to_id assert_equal 2, issue.assigned_to_id
end end
end
def test_disabled_auto_assigned_to def test_disabled_auto_assigned_to
with_additionals_settings(issue_status_change: '0', with_additionals_settings(issue_status_change: '0',
issue_auto_assign: '0', issue_auto_assign: '0',
issue_auto_assign_status: ['1'], issue_auto_assign_status: ['1'],
issue_auto_assign_role: '1') issue_auto_assign_role: '1') do
issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create') issue = Issue.new(project_id: 1, tracker_id: 1, author_id: 3, subject: 'test_create')
assert issue.save assert issue.save
assert_nil issue.assigned_to_id assert_nil issue.assigned_to_id
end end
end
end end

View File

@@ -11,19 +11,20 @@ class WatcherTest < ActiveSupport::TestCase
@author = User.find(1) @author = User.find(1)
@assigned_user = User.find(2) @assigned_user = User.find(2)
@changing_user = User.find(4) @changing_user = User.find(4)
with_additionals_settings(issue_autowatch_involved: 1)
end end
def test_new_issue_with_no_autowatch def test_new_issue_with_no_autowatch
with_additionals_settings(issue_autowatch_involved: 0) with_additionals_settings(issue_autowatch_involved: 0) do
User.current = @author User.current = @author
issue = Issue.generate(author_id: @author.id) issue = Issue.generate(author_id: @author.id)
issue.save issue.save
assert_equal 0, issue.watchers.count assert_equal 0, issue.watchers.count
assert_not issue.watched_by?(@author) assert_not issue.watched_by?(@author)
end end
end
def test_new_issue_with_no_autowatch_by_user def test_new_issue_with_no_autowatch_by_user
with_additionals_settings(issue_autowatch_involved: 1) do
User.current = @author User.current = @author
User.current.pref.update_attribute :autowatch_involved_issue, false User.current.pref.update_attribute :autowatch_involved_issue, false
@@ -32,16 +33,20 @@ class WatcherTest < ActiveSupport::TestCase
assert_equal 0, issue.watchers.count assert_equal 0, issue.watchers.count
assert_not issue.watched_by?(@author) assert_not issue.watched_by?(@author)
end end
end
def test_new_issue_with_author_watch_only def test_new_issue_with_author_watch_only
with_additionals_settings(issue_autowatch_involved: 1) do
User.current = @author User.current = @author
issue = Issue.generate(author_id: @author.id) issue = Issue.generate(author_id: @author.id)
issue.save issue.save
assert_equal 1, issue.watchers.count assert_equal 1, issue.watchers.count
assert issue.watched_by?(@author) assert issue.watched_by?(@author)
end end
end
def test_new_issue_with_author_and_assigned_to_watchers def test_new_issue_with_author_and_assigned_to_watchers
with_additionals_settings(issue_autowatch_involved: 1) do
User.current = @author User.current = @author
issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user)
issue.save issue.save
@@ -50,8 +55,10 @@ class WatcherTest < ActiveSupport::TestCase
assert issue.watched_by?(@author) assert issue.watched_by?(@author)
assert issue.watched_by?(@assigned_user) assert issue.watched_by?(@assigned_user)
end end
end
def test_issue_do_not_add_author_with_user_change def test_issue_do_not_add_author_with_user_change
with_additionals_settings(issue_autowatch_involved: 1) do
User.current = @author User.current = @author
issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user)
@@ -70,8 +77,10 @@ class WatcherTest < ActiveSupport::TestCase
assert issue.watched_by?(@changing_user) assert issue.watched_by?(@changing_user)
assert issue.watched_by?(@assigned_user) assert issue.watched_by?(@assigned_user)
end end
end
def test_issue_do_not_add_assigned_to_with_user_change def test_issue_do_not_add_assigned_to_with_user_change
with_additionals_settings(issue_autowatch_involved: 1) do
User.current = @author User.current = @author
issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user) issue = Issue.generate(author_id: @author.id, assigned_to: @assigned_user)
@@ -90,4 +99,5 @@ class WatcherTest < ActiveSupport::TestCase
assert issue.watched_by?(@author) assert issue.watched_by?(@author)
assert issue.watched_by?(@changing_user) assert issue.watched_by?(@changing_user)
end end
end
end end