diff --git a/.travis.yml b/.travis.yml index 0bda81ea..7f3238f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ sudo: false language: ruby cache: bundler rvm: - - 2.2.7 - - 2.3.4 - 2.4.1 + - 2.3.4 + - 2.2.7 branches: only: @@ -14,9 +14,9 @@ addons: postgresql: "9.6" env: - - REDMINE_VER=3.2-stable - - REDMINE_VER=3.3-stable - REDMINE_VER=3.4-stable + - REDMINE_VER=3.3-stable + - REDMINE_VER=3.2-stable # - REDMINE_VER=master install: "echo skip bundle install" diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e1cde7bb..b10161dc 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,7 @@ Changelog - updated bootstrap-datepicker to v1.8.0 - updated d3plus to v2.0.0-alpha.17 - ruby 2.2.0 is required +- Redmine 3.4 is required 2.0.12 ++++++ diff --git a/db/migrate/001_add_autowatch_involved_issue_to_user.rb b/db/migrate/001_add_autowatch_involved_issue_to_user.rb index 290e898a..594d09b1 100644 --- a/db/migrate/001_add_autowatch_involved_issue_to_user.rb +++ b/db/migrate/001_add_autowatch_involved_issue_to_user.rb @@ -1,4 +1,4 @@ -class AddAutowatchInvolvedIssueToUser < ActiveRecord::Migration +class AddAutowatchInvolvedIssueToUser < Rails.version < '5.2' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2] def change add_column :user_preferences, :autowatch_involved_issue, :boolean, default: true, null: false end diff --git a/docs/index.rst b/docs/index.rst index 0861a27e..6c7f241d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -38,11 +38,11 @@ Requirements ------------ +--------------------+----------------------+ -| `Redmine`_ version | >= 3.0.0 | +| `Redmine`_ version | >= 3.4.0 | +--------------------+----------------------+ | `Ruby`_ version | >= 2.2.0 | +--------------------+----------------------+ -| Gem packages | see `Gemfile`_ | +| Gem packages | see `Gemfile`_ | +--------------------+----------------------+ diff --git a/init.rb b/init.rb index 1dd65b47..9c1555c3 100644 --- a/init.rb +++ b/init.rb @@ -31,7 +31,7 @@ Redmine::Plugin.register :additionals do end # required redmine version - requires_redmine version_or_higher: '3.0.0' + requires_redmine version_or_higher: '3.4.0' menu :admin_menu, :additionals, { controller: 'settings', action: 'plugin', id: 'additionals' }, caption: :label_additionals diff --git a/lib/additionals.rb b/lib/additionals.rb index d043c8fc..29bf24c2 100644 --- a/lib/additionals.rb +++ b/lib/additionals.rb @@ -49,7 +49,12 @@ module Additionals end def settings - ActionController::Parameters.new(Setting[:plugin_additionals]) + @settings ||= ActionController::Parameters.new(Setting[:plugin_additionals]) + @settings + end + + def change_settings=(overwrites) + @settings.merge!(overwrites) end def setting?(value) diff --git a/lib/additionals/patches/application_controller_patch.rb b/lib/additionals/patches/application_controller_patch.rb index 59456bb1..8324ecd5 100644 --- a/lib/additionals/patches/application_controller_patch.rb +++ b/lib/additionals/patches/application_controller_patch.rb @@ -4,7 +4,8 @@ module Additionals def self.included(base) base.send(:include, InstanceMethods) base.class_eval do - alias_method_chain :user_setup, :additionals + alias_method :user_setup_without_additionals, :user_setup + alias_method :user_setup, :user_setup_with_additionals end end diff --git a/lib/additionals/patches/issue_patch.rb b/lib/additionals/patches/issue_patch.rb index fb919a47..6bdada7b 100644 --- a/lib/additionals/patches/issue_patch.rb +++ b/lib/additionals/patches/issue_patch.rb @@ -4,7 +4,8 @@ module Additionals def self.included(base) base.send(:include, InstanceMethods) base.class_eval do - alias_method_chain :editable?, :closed_edit + alias_method :editable_without_additionals?, :editable? + alias_method :editable?, :editable_with_additionals? # TODO: working on issues of dependencies (aroud 20 redmine tests failed with it) # validate :validate_change_on_closed validate :validate_open_sub_issues @@ -49,8 +50,8 @@ module Additionals !closed? || user.allowed_to?(:log_time_on_closed_issues, project) end - def editable_with_closed_edit?(user = User.current) - return false unless editable_without_closed_edit?(user) + def editable_with_additionals?(user = User.current) + return false unless editable_without_additionals?(user) return true unless closed? user.allowed_to?(:edit_closed_issues, project) end diff --git a/lib/additionals/patches/time_entry_patch.rb b/lib/additionals/patches/time_entry_patch.rb index 1f6fc65d..b391e974 100644 --- a/lib/additionals/patches/time_entry_patch.rb +++ b/lib/additionals/patches/time_entry_patch.rb @@ -4,7 +4,8 @@ module Additionals def self.included(base) base.send(:include, InstanceMethods) base.class_eval do - alias_method_chain :editable_by?, :additionals + alias_method :editable_by_without_additionals?, :editable_by? + alias_method :editable_by?, :editable_by_with_additionals? validate :validate_issue_allowed end end diff --git a/lib/additionals/patches/wiki_controller_patch.rb b/lib/additionals/patches/wiki_controller_patch.rb index c01251f3..357d4451 100644 --- a/lib/additionals/patches/wiki_controller_patch.rb +++ b/lib/additionals/patches/wiki_controller_patch.rb @@ -6,7 +6,8 @@ module Additionals def self.included(base) base.send(:include, InstanceMethods) base.class_eval do - alias_method_chain :respond_to, :additionals + alias_method :respond_to_without_additionals, :respond_to + alias_method :respond_to, :respond_to_with_additionals end end end diff --git a/lib/additionals/patches/wiki_patch.rb b/lib/additionals/patches/wiki_patch.rb index 36509b53..31644760 100644 --- a/lib/additionals/patches/wiki_patch.rb +++ b/lib/additionals/patches/wiki_patch.rb @@ -7,7 +7,8 @@ module Additionals def self.included(base) base.send(:include, InstanceMethodsForAdditionalsWiki) base.class_eval do - alias_method_chain :sidebar, :additionals + alias_method :sidebar_without_additionals, :sidebar + alias_method :sidebar, :sidebar_with_additionals end end end diff --git a/lib/additionals/patches/wiki_pdf_helper_patch.rb b/lib/additionals/patches/wiki_pdf_helper_patch.rb index 0cd49ec9..85e95267 100644 --- a/lib/additionals/patches/wiki_pdf_helper_patch.rb +++ b/lib/additionals/patches/wiki_pdf_helper_patch.rb @@ -4,7 +4,8 @@ module Additionals def self.included(base) base.send(:include, InstanceMethods) base.class_eval do - alias_method_chain :wiki_page_to_pdf, :additionals + alias_method :wiki_page_to_pdf_without_additionals, :wiki_page_to_pdf + alias_method :wiki_page_to_pdf, :wiki_page_to_pdf_with_additionals end end diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index fa4ab002..1c4cf839 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -5,18 +5,14 @@ class AccountControllerTest < Additionals::ControllerTest def setup Setting.default_language = 'en' - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new User.current = nil end def test_get_login_with_welcome_text - Setting.plugin_additionals = ActionController::Parameters.new( - account_login_bottom: 'Lore impsuum' - ) + with_additionals_settings(account_login_bottom: 'Lore impsuum') + get :login assert_response :success - assert_template 'login' assert_select 'input[name=username]' assert_select 'input[name=password]' @@ -24,13 +20,10 @@ class AccountControllerTest < Additionals::ControllerTest end def test_get_login_without_welcome_text - Setting.plugin_additionals = ActionController::Parameters.new( - account_login_bottom: '' - ) + with_additionals_settings(account_login_bottom: '') get :login assert_response :success - assert_template 'login' assert_select 'input[name=username]' assert_select 'input[name=password]' diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 6eb17770..f1fbe450 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -86,10 +86,7 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'show assign-to-me on issue' do - Setting.plugin_additionals = ActionController::Parameters.new( - issue_assign_to_me: 1 - ) - + with_additionals_settings(issue_assign_to_me: 1) @request.session[:user_id] = 2 get :show, params: { id: 2 } @@ -97,10 +94,7 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'don\'t show assign-to-me on issue without activation' do - Setting.plugin_additionals = ActionController::Parameters.new( - issue_assign_to_me: 0 - ) - + with_additionals_settings(issue_assign_to_me: 0) @request.session[:user_id] = 2 get :show, params: { id: 2 } @@ -108,10 +102,7 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'don\'t show assign-to-me on issue with already assigned_to me' do - Setting.plugin_additionals = ActionController::Parameters.new( - issue_assign_to_me: 1 - ) - + with_additionals_settings(issue_assign_to_me: 1) @request.session[:user_id] = 2 get :show, params: { id: 4 } @@ -119,10 +110,7 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'show change status in issue sidebar' do - Setting.plugin_additionals = ActionController::Parameters.new( - issue_change_status_in_sidebar: 1 - ) - + with_additionals_settings(issue_change_status_in_sidebar: 1) @request.session[:user_id] = 2 get :show, params: { id: 2 } @@ -130,10 +118,7 @@ class IssuesControllerTest < Additionals::ControllerTest end test 'don\'t show change status in issue sidebar without activation' do - Setting.plugin_additionals = ActionController::Parameters.new( - issue_change_status_in_sidebar: 0 - ) - + with_additionals_settings(issue_change_status_in_sidebar: 0) @request.session[:user_id] = 2 get :show, params: { id: 2 } diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index e8f16ca1..e9eb98fe 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -16,34 +16,26 @@ class ProjectsControllerTest < Additionals::ControllerTest def setup Setting.default_language = 'en' - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new User.current = nil end def test_show_overview_content - Setting.plugin_additionals = ActionController::Parameters.new( - project_overview_content: 'Lore impsuum' - ) + with_additionals_settings(project_overview_content: 'Lore impsuum') @request.session[:user_id] = 4 get :show, params: { id: 1 } assert_response :success - assert_template 'show' assert_select 'div.project-content', text: /Lore impsuum/ end def test_do_not_show_overview_content_box - Setting.plugin_additionals = ActionController::Parameters.new( - project_overview_content: '' - ) + with_additionals_settings(project_overview_content: '') @request.session[:user_id] = 4 get :show, params: { id: 1 } assert_response :success - assert_template 'show' assert_select 'div.project-content', count: 0 end end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index bc611a45..018703c1 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -23,10 +23,7 @@ class UsersControllerTest < Additionals::ControllerTest end def test_show_new_issue_on_profile - Setting.plugin_additionals = ActionController::Parameters.new( - new_issue_on_profile: 1 - ) - + with_additionals_settings(new_issue_on_profile: 1) @request.session[:user_id] = 2 get :show, params: { id: 2 } @@ -34,10 +31,7 @@ class UsersControllerTest < Additionals::ControllerTest end def test_not_show_new_issue_on_profile_without_activated - Setting.plugin_additionals = ActionController::Parameters.new( - new_issue_on_profile: 0 - ) - + with_additionals_settings(new_issue_on_profile: 0) @request.session[:user_id] = 2 get :show, params: { id: 2 } diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb index c8de3bfd..a5702096 100644 --- a/test/functional/welcome_controller_test.rb +++ b/test/functional/welcome_controller_test.rb @@ -5,86 +5,60 @@ class WelcomeControllerTest < Additionals::ControllerTest def setup Setting.default_language = 'en' - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new User.current = nil end def test_show_with_overview_right - Setting.plugin_additionals = ActionController::Parameters.new( - overview_right: 'Lore impsuum' - ) + with_additionals_settings(overview_right: 'Lore impsuum') @request.session[:user_id] = 4 get :index assert_response :success - assert_template 'index' - assert_not_nil assigns(:news) assert_select 'div.overview-right', text: /Lore impsuum/ end def test_show_without_overview_right - Setting.plugin_additionals = ActionController::Parameters.new( - overview_right: '' - ) + with_additionals_settings(overview_right: '') @request.session[:user_id] = 4 get :index assert_response :success - assert_template 'index' - assert_not_nil assigns(:news) assert_select 'div.overview-right', count: 0 end def test_show_with_overview_bottom - Setting.plugin_additionals = ActionController::Parameters.new( - overview_bottom: 'Lore impsuum' - ) + with_additionals_settings(overview_bottom: 'Lore impsuum') @request.session[:user_id] = 4 get :index assert_response :success - assert_template 'index' - assert_not_nil assigns(:news) assert_select 'div.overview-bottom', text: /Lore impsuum/ end def test_show_without_overview_bottom - Setting.plugin_additionals = ActionController::Parameters.new( - overview_bottom: '' - ) + with_additionals_settings(overview_bottom: '') @request.session[:user_id] = 4 get :index assert_response :success - assert_template 'index' - assert_not_nil assigns(:news) assert_select 'div.overview-bottom', count: 0 end def test_show_with_overview_top - Setting.plugin_additionals = ActionController::Parameters.new( - overview_top: 'Lore impsuum' - ) + with_additionals_settings(overview_top: 'Lore impsuum') @request.session[:user_id] = 4 get :index assert_response :success - assert_template 'index' - assert_not_nil assigns(:news) assert_select 'div.overview-top', text: /Lore impsuum/ end def test_show_without_overview_top - Setting.plugin_additionals = ActionController::Parameters.new( - overview_top: '' - ) + with_additionals_settings(overview_top: '') @request.session[:user_id] = 4 get :index assert_response :success - assert_template 'index' - assert_not_nil assigns(:news) assert_select 'div.overview-top', count: 0 end end diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index d0f00b38..ee044109 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -41,7 +41,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'iframe[src=?]', '//www.youtube-nocookie.com/embed/KMU0tzLwhbE' end @@ -52,7 +51,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'iframe', src: %r{^https\://www\.meteoblue\.com/en/weather/widget/daily/(.*)} end @@ -63,7 +61,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'iframe[src=?]', '//player.vimeo.com/video/142849533' end @@ -74,7 +71,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'iframe[src=?]', '//www.slideshare.net/slideshow/embed_code/57941706' end @@ -85,7 +81,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'iframe[src=?]', 'https://www.redmine.org/' end @@ -96,7 +91,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a.twitter' assert_select 'a[href=?]', 'https://twitter.com/alphanodes', text: '@alphanodes' @@ -125,7 +119,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a.reddit' assert_select 'a[href=?]', 'https://www.reddit.com/r/redmine', text: 'r/redmine' @@ -154,7 +147,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'span.last-updated-by' assert_select 'a[href=?]', '/users/2', text: 'jsmith' @@ -167,7 +159,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'span.last-updated-at' assert_select 'a[href=?]', '/projects/ecookbook/activity' end @@ -179,7 +170,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'div.recently-updated' end @@ -190,7 +180,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'div.month-calendar' end @@ -201,7 +190,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'div.wiki div.user' end @@ -212,7 +200,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'div.wiki a.macro-new-issue' end @@ -223,7 +210,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'div.wiki div.user' end @@ -234,7 +220,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'div.wiki div.projects li.project' end @@ -245,7 +230,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'script[src=?]', 'https://gist.github.com/plentz/6737338.js' end @@ -256,7 +240,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'script[src=?]', 'https://s3.tradingview.com/tv.js' end @@ -267,7 +250,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'div.wiki div.cryptocompare', text: %r{https:\/\/widgets\.cryptocompare\.com\/serve\/v3\/coin\/header\?fsyms=BTC,ETH&tsyms=EUR} end @@ -279,7 +261,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'div.wiki span.current-date', User.current.today.cweek.to_s end @@ -290,7 +271,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a[href=?]', '/issues/2', text: 'Add ingredients categories' end @@ -302,7 +282,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a[href=?]', '/issues/2', text: '#2 Add ingredients categories' end @@ -314,7 +293,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a[href=?]', '/issues/2', text: '#2 Add ingredients categories' assert_select 'div.issue-macro-comment', 0 @@ -327,7 +305,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a[href=?]', '/issues/2', text: '#2 Add ingredients categories' assert_select 'div.issue-macro-comment' @@ -340,7 +317,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a[href=?]', '/issues/2', text: '#2 Add ingredients categories' end @@ -352,7 +328,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a[href=?]', '/users/1', text: 'Redmine Admin' end @@ -364,7 +339,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a.user', text: 'Redmine Admin' assert_select 'a[href=?]', '/users/1', text: 'Redmine Admin' @@ -377,7 +351,6 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a[href=?]', '/users/2', text: 'jsmith' end @@ -389,57 +362,48 @@ class WikiControllerTest < Additionals::ControllerTest get :show, params: { project_id: 1, id: @page_name } assert_response :success - assert_template 'show' assert_select 'a.user', text: 'John Smith' assert_select 'a[href=?]', '/users/2', text: 'John Smith' end def test_show_wiki_with_header - Setting.plugin_additionals = ActionController::Parameters.new( - global_wiki_header: 'Lore impsuum' - ) + with_additionals_settings(global_wiki_header: 'Lore impsuum') + get :show, params: { project_id: 1, id: 'Another_page' } assert_response :success - assert_template 'show' assert_select 'div#wiki_extentions_header', text: /Lore impsuum/ end def test_show_wiki_without_header - Setting.plugin_additionals = ActionController::Parameters.new( - global_wiki_header: '' - ) + with_additionals_settings(global_wiki_header: '') + get :show, params: { project_id: 1, id: 'Another_page' } assert_response :success - assert_template 'show' assert_select 'div#wiki_extentions_header', count: 0 end def test_show_wiki_with_footer - Setting.plugin_additionals = ActionController::Parameters.new( - global_wiki_footer: 'Lore impsuum' - ) + with_additionals_settings(global_wiki_footer: 'Lore impsuum') + get :show, params: { project_id: 1, id: 'Another_page' } assert_response :success - assert_template 'show' assert_select 'div#wiki_extentions_footer', text: /Lore impsuum/ end def test_show_wiki_without_footer - Setting.plugin_additionals = ActionController::Parameters.new( - global_wiki_footer: '' - ) + with_additionals_settings(global_wiki_footer: '') + get :show, params: { project_id: 1, id: 'Another_page' } assert_response :success - assert_template 'show' assert_select 'div#wiki_extentions_footer', count: 0 end end diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb index 9ef879a0..2e144848 100644 --- a/test/integration/api_test/issues_test.rb +++ b/test/integration/api_test/issues_test.rb @@ -39,12 +39,10 @@ module ApiTest end test 'POST /issues.xml should create an issue with the attributes' do - Setting.plugin_additionals = ActionController::Parameters.new( - issue_status_change: '0', - issue_auto_assign: '0', - issue_auto_assign_status: ['1'], - issue_auto_assign_role: '1' - ) + with_additionals_settings(issue_status_change: '0', + issue_auto_assign: '0', + issue_auto_assign_status: ['1'], + issue_auto_assign_role: '1') payload = <<-XML @@ -72,12 +70,10 @@ module ApiTest end test 'POST /issues.xml should create an issue with auto assigned_to_id' do - Setting.plugin_additionals = ActionController::Parameters.new( - issue_status_change: '0', - issue_auto_assign: '1', - issue_auto_assign_status: ['1'], - issue_auto_assign_role: '1' - ) + with_additionals_settings(issue_status_change: '0', + issue_auto_assign: '1', + issue_auto_assign_status: ['1'], + issue_auto_assign_role: '1') payload = <<-XML diff --git a/test/integration/common_views_test.rb b/test/integration/common_views_test.rb index 32d9d1a7..ea119284 100644 --- a/test/integration/common_views_test.rb +++ b/test/integration/common_views_test.rb @@ -1,6 +1,5 @@ require File.expand_path('../../test_helper', __FILE__) -# Additionals integration tests class CommonViewsTest < Redmine::IntegrationTest fixtures :projects, :users, @@ -19,10 +18,6 @@ class CommonViewsTest < Redmine::IntegrationTest def setup Additionals::TestCase.prepare - - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - @request.env['HTTP_REFERER'] = '/' end test 'View user' do diff --git a/test/test_helper.rb b/test/test_helper.rb index b3201087..44ab194b 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,19 +15,27 @@ end require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') -# Additionals helper class for tests module Additionals - class ControllerTest < ActionController::TestCase - # can be removed if Redmine 3.4 and higher is supported only - def process(action, http_method = 'GET', *args) - parameters, _session, _flash = *args - if args.size == 1 && parameters[:xhr] == true - xhr http_method.downcase.to_sym, action, parameters.except(:xhr) - elsif parameters && (parameters.key?(:params) || parameters.key?(:session) || parameters.key?(:flash)) - super action, http_method, parameters[:params], parameters[:session], parameters[:flash] - else - super - end + module TestHelper + def with_additionals_settings(settings) + Additionals.change_settings = settings + end + end + + class ControllerTest < Redmine::ControllerTest + def compatible_request(type, action, parameters = {}) + return send(type, action, params: parameters) if Rails.version >= '5.2' + send(type, action, parameters) + end + + def compatible_xhr_request(type, action, parameters = {}) + return send(type, action, params: parameters, xhr: true) if Rails.version >= '5.2' + xhr type, action, parameters + end + + def compatible_api_request(type, action, parameters = {}, headers = {}) + return send(type, action, params: parameters, headers: headers) if Rails.version >= '5.2' + send(type, action, parameters, headers) end end @@ -69,3 +77,5 @@ module Additionals end end end + +include Additionals::TestHelper diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 6e4d6a73..6cec4a40 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -64,12 +64,10 @@ class IssueTest < ActiveSupport::TestCase end def test_auto_assigned_to - Setting.plugin_additionals = ActionController::Parameters.new( - issue_status_change: '0', - issue_auto_assign: '1', - issue_auto_assign_status: ['1'], - issue_auto_assign_role: '1' - ) + 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 @@ -77,12 +75,10 @@ class IssueTest < ActiveSupport::TestCase end def test_disabled_auto_assigned_to - Setting.plugin_additionals = ActionController::Parameters.new( - issue_status_change: '0', - issue_auto_assign: '0', - issue_auto_assign_status: ['1'], - issue_auto_assign_role: '1' - ) + 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 diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index e76aaf62..be3c070d 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -11,17 +11,11 @@ class WatcherTest < ActiveSupport::TestCase @author = User.find(1) @assigned_user = User.find(2) @changing_user = User.find(4) - - Setting.plugin_additionals = ActionController::Parameters.new( - issue_autowatch_involved: 1 - ) + with_additionals_settings(issue_autowatch_involved: 1) end def test_new_issue_with_no_autowatch - Setting.plugin_additionals = ActionController::Parameters.new( - issue_autowatch_involved: 0 - ) - + with_additionals_settings(issue_autowatch_involved: 0) User.current = @author issue = Issue.generate(author_id: @author.id) issue.save