OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix/hook service to openproject (#9214)
ulferts5cb227796cd6
diff --git a/app/helpers/hook_helper.rb b/app/helpers/hook_helper.rbindex 32032002d09..0f267766b15 100644--- a/app/helpers/hook_helper.rb+++ b/app/helpers/hook_helper.rb@@ -22,12 +22,12 @@ module HookHelperdef call_hook(hook, context = {})if is_a?(ActionController::Base)default_context = { controller: self, project: @project, request: request, hook_caller: self }- Redmine::Hook.call_hook(hook, default_context.merge(context))+ OpenProject::Hook.call_hook(hook, default_context.merge(context))elsedefault_context = { project: @project, hook_caller: self }default_context[:controller] = controller if respond_to?(:controller)default_context[:request] = request if respond_to?(:request)- Redmine::Hook.call_hook(hook, default_context.merge(context)).join(' ').html_safe+ OpenProject::Hook.call_hook(hook, default_context.merge(context)).join(' ').html_safeendendenddiff --git a/app/models/changeset.rb b/app/models/changeset.rbindex e751ec81b13..cb2c9e26dc5 100644--- a/app/models/changeset.rb+++ b/app/models/changeset.rb@@ -241,8 +241,8 @@ class Changeset < ApplicationRecordunless Setting.commit_fix_done_ratio.blank?work_package.done_ratio = Setting.commit_fix_done_ratio.to_iend- Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,- changeset: self, issue: work_package)+ OpenProject::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update,+ changeset: self, issue: work_package)if !work_package.save(validate: false) && loggerlogger.warn("Work package ##{work_package.id} could not be saved by changeset #{id}: #{work_package.errors.full_messages}")enddiff --git a/app/models/work_package/hooks.rb b/app/models/work_package/hooks.rbindex d98aa832b6e..7556877a30d 100644--- a/app/models/work_package/hooks.rb+++ b/app/models/work_package/hooks.rb@@ -39,12 +39,12 @@ module WorkPackage::Hooksdef call_after_create_hookcontext = { work_package: self }- Redmine::Hook.call_hook :work_package_after_create, context+ OpenProject::Hook.call_hook :work_package_after_create, contextenddef call_after_update_hookcontext = { work_package: self }- Redmine::Hook.call_hook :work_package_after_update, context+ OpenProject::Hook.call_hook :work_package_after_update, contextendenddiff --git a/lib/open_project.rb b/lib/open_project.rbindex 4571b43a6f6..bdf2eb2bd62 100644--- a/lib/open_project.rb+++ b/lib/open_project.rb@@ -35,7 +35,7 @@ require 'open_project/logging/log_delegator'require 'open_project/patches'require 'redmine/mime_type'require 'open_project/custom_styles/design'-require 'redmine/hook'+require 'open_project/hook'require 'open_project/hooks'require 'redmine/plugin'diff --git a/lib/redmine/hook.rb b/lib/open_project/hook.rbsimilarity index 86%rename from lib/redmine/hook.rbrename to lib/open_project/hook.rbindex b69f1bf8e77..aaca857a43c 100644--- a/lib/redmine/hook.rb+++ b/lib/open_project/hook.rb@@ -28,42 +28,43 @@# See docs/COPYRIGHT.rdoc for more details.#++-module Redmine+module OpenProjectmodule Hook- @@listener_classes = []- @@listeners = nil- @@hook_listeners = {}-class << self# Adds a listener class.- # Automatically called when a class inherits from Redmine::Hook::Listener.+ # Automatically called when a class inherits from OpenProject::Hook::Listener.def add_listener(klass)- raise 'Hooks must include Singleton module.' unless klass.included_modules.include?(Singleton)+ raise ArgumentError, 'Hooks must include Singleton module.' unless klass.included_modules.include?(Singleton)- @@listener_classes << klass+ listener_classes << klassclear_listeners_instancesend# Returns all the listener instances.def listeners- @@listeners ||= @@listener_classes.map(&:instance)+ @listeners ||= listener_classes.map(&:instance)+ end++ def listener_classes+ @listener_classes ||= []end# Returns the listener instances for the given hook.def hook_listeners(hook)- @@hook_listeners[hook] ||= listeners.select { |listener| listener.respond_to?(hook) }+ @hook_listeners ||= {}+ @hook_listeners[hook] ||= listeners.select { |listener| listener.respond_to?(hook) }end# Clears all the listeners.def clear_listeners- @@listener_classes = []+ @listener_classes = []clear_listeners_instancesend# Clears all the listeners instances.def clear_listeners_instances- @@listeners = nil- @@hook_listeners = {}+ @listeners = nil+ @hook_listeners = {}end# Calls a hook.@@ -87,7 +88,7 @@ module Redmine# Registers the listenerdef self.inherited(child)- Redmine::Hook.add_listener(child)+ OpenProject::Hook.add_listener(child)superendend@@ -120,7 +121,7 @@ module Redmine# Helper method to directly render a partial using the context:#- # class MyHook < Redmine::Hook::ViewListener+ # class MyHook < OpenProject::Hook::ViewListener# render_on :view_issues_show_details_bottom, partial: "show_more_data"# end#diff --git a/lib/open_project/hooks/view_account_login_auth_provider.rb b/lib/open_project/hooks/view_account_login_auth_provider.rbindex adabaabe822..13e8e3dd4e4 100644--- a/lib/open_project/hooks/view_account_login_auth_provider.rb+++ b/lib/open_project/hooks/view_account_login_auth_provider.rb@@ -30,7 +30,7 @@ module OpenProjectmodule Hooks### Hook called in the login forms which displays the different auth providers- class ViewAccountLoginAuthProvider < Redmine::Hook::ViewListener+ class ViewAccountLoginAuthProvider < OpenProject::Hook::ViewListenerrender_on :view_account_login_auth_provider,partial: 'hooks/login/auth_provider'enddiff --git a/lib/open_project/hooks/view_account_login_bottom.rb b/lib/open_project/hooks/view_account_login_bottom.rbindex b08f79868e9..72a34730e2e 100644--- a/lib/open_project/hooks/view_account_login_bottom.rb+++ b/lib/open_project/hooks/view_account_login_bottom.rb@@ -28,7 +28,7 @@module OpenProjectmodule Hooks- class ViewAccountLoginBottom < Redmine::Hook::ViewListener+ class ViewAccountLoginBottom < OpenProject::Hook::ViewListenerrender_on :view_account_login_bottom, partial: 'announcements/show'endenddiff --git a/modules/auth_plugins/lib/open_project/auth_plugins/hooks.rb b/modules/auth_plugins/lib/open_project/auth_plugins/hooks.rbindex 601abd82453..818dcae5132 100644--- a/modules/auth_plugins/lib/open_project/auth_plugins/hooks.rb+++ b/modules/auth_plugins/lib/open_project/auth_plugins/hooks.rb@@ -29,7 +29,7 @@#++module OpenProject::AuthPlugins- class Hooks < Redmine::Hook::ViewListener+ class Hooks < OpenProject::Hook::ViewListenerrender_on :view_account_login_auth_provider, partial: 'hooks/login/providers'render_on :view_layouts_base_html_head, partial: 'hooks/login/providers_css'enddiff --git a/modules/backlogs/lib/open_project/backlogs/hooks.rb b/modules/backlogs/lib/open_project/backlogs/hooks.rbindex 21ee86ed170..7712a91ce15 100644--- a/modules/backlogs/lib/open_project/backlogs/hooks.rb+++ b/modules/backlogs/lib/open_project/backlogs/hooks.rb@@ -27,7 +27,7 @@#++module OpenProject::Backlogs::Hooks- class LayoutHook < Redmine::Hook::ViewListener+ class LayoutHook < OpenProject::Hook::ViewListenerinclude RbCommonHelperdef view_versions_show_bottom(context = {})diff --git a/modules/backlogs/lib/open_project/backlogs/hooks/user_settings_hook.rb b/modules/backlogs/lib/open_project/backlogs/hooks/user_settings_hook.rbindex c604cb934f3..7cd5d36b958 100644--- a/modules/backlogs/lib/open_project/backlogs/hooks/user_settings_hook.rb+++ b/modules/backlogs/lib/open_project/backlogs/hooks/user_settings_hook.rb@@ -26,7 +26,7 @@# See docs/COPYRIGHT.rdoc for more details.#++-class OpenProject::Backlogs::Hooks::UserSettingsHook < Redmine::Hook::ViewListener+class OpenProject::Backlogs::Hooks::UserSettingsHook < OpenProject::Hook::ViewListener# Updates the backlogs settings before saving the user## Context:diff --git a/modules/bim/lib/open_project/bim/hooks.rb b/modules/bim/lib/open_project/bim/hooks.rbindex 4f3c6e26ee5..42ba8ea4c08 100644--- a/modules/bim/lib/open_project/bim/hooks.rb+++ b/modules/bim/lib/open_project/bim/hooks.rb@@ -27,7 +27,7 @@#+module OpenProject::Bim::Hooks- class Hook < Redmine::Hook::Listener+ class Hook < OpenProject::Hook::Listenerinclude ActionView::Helpers::TagHelperinclude ActionView::Contextinclude WorkPackagesHelperdiff --git a/modules/budgets/lib/budgets/hooks/work_package_hook.rb b/modules/budgets/lib/budgets/hooks/work_package_hook.rbindex 28b3afb02e0..e30736ba242 100644--- a/modules/budgets/lib/budgets/hooks/work_package_hook.rb+++ b/modules/budgets/lib/budgets/hooks/work_package_hook.rb@@ -26,7 +26,7 @@# See docs/COPYRIGHT.rdoc for more details.#++-class Budgets::Hooks::WorkPackageHook < Redmine::Hook::ViewListener+class Budgets::Hooks::WorkPackageHook < OpenProject::Hook::ViewListener# Updates the cost object after a move## Context:diff --git a/modules/xls_export/lib/open_project/xls_export/hooks/cost_report_hook.rb b/modules/xls_export/lib/open_project/xls_export/hooks/cost_report_hook.rbindex 59a6569eb0d..7b8508dea46 100644--- a/modules/xls_export/lib/open_project/xls_export/hooks/cost_report_hook.rb+++ b/modules/xls_export/lib/open_project/xls_export/hooks/cost_report_hook.rb@@ -1,5 +1,5 @@module OpenProject::XlsExport::Hooks- class CostReportHook < Redmine::Hook::ViewListener+ class CostReportHook < OpenProject::Hook::ViewListenerrender_on :view_cost_report_toolbar, partial: 'hooks/xls_report/view_cost_report_toolbar'endenddiff --git a/modules/xls_export/lib/open_project/xls_export/hooks/work_package_hook.rb b/modules/xls_export/lib/open_project/xls_export/hooks/work_package_hook.rbindex 34451aa5fdf..89034fdaae6 100644--- a/modules/xls_export/lib/open_project/xls_export/hooks/work_package_hook.rb+++ b/modules/xls_export/lib/open_project/xls_export/hooks/work_package_hook.rb@@ -1,5 +1,5 @@module OpenProject::XlsExport::Hooks- class WorkPackageHook < Redmine::Hook::ViewListener+ class WorkPackageHook < OpenProject::Hook::ViewListenerdef link_to_xls(context, label, options = {})url = {project_id: context[:project],diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rbindex 162aa1353ed..070b5558f2d 100644--- a/spec/controllers/account_controller_spec.rb+++ b/spec/controllers/account_controller_spec.rb@@ -29,7 +29,7 @@require 'spec_helper'describe AccountController, type: :controller do- class UserHook < Redmine::Hook::ViewListener+ class UserHook < OpenProject::Hook::ViewListenerattr_reader :registered_user, :first_login_userdef user_registered(context)diff --git a/spec/helpers/hook_helper_spec.rb b/spec/helpers/hook_helper_spec.rbnew file mode 100644index 00000000000..8e172082fe7--- /dev/null+++ b/spec/helpers/hook_helper_spec.rb@@ -0,0 +1,117 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#+++require 'spec_helper'++describe HookHelper do+ describe '#call_hook' do+ context 'when called within a controller' do+ let(:test_hook_controller_class) do+ # Also tests that the application controller has the model included+ Class.new(ApplicationController)+ end+ let(:instance) do+ test_hook_controller_class.new.tap do |inst|+ inst.instance_variable_set(:@project, project)+ allow(inst)+ .to receive(:request)+ .and_return(request)+ end+ end+ let(:project) do+ instance_double('Project')+ end+ let(:request) do+ instance_double('ActiveSupport::Request')+ end++ it 'adds to the context' do+ allow(OpenProject::Hook)+ .to receive(:call_hook)++ instance.call_hook(:some_hook_identifier, {})++ expect(OpenProject::Hook)+ .to have_received(:call_hook)+ .with(:some_hook_identifier, { project: project,+ controller: instance,+ request: request,+ hook_caller: instance })+ end+ end++ context 'when called within a view' do+ let(:test_hook_view_class) do+ # Also tests that the application controller has the model included+ Class.new(ActionView::Base) do+ include HookHelper+ end+ end+ let(:instance) do+ test_hook_view_class+ .new(ActionView::LookupContext.new(Rails.root.join('app/views')), {}, nil)+ .tap do |inst|+ inst.instance_variable_set(:@project, project)+ allow(inst)+ .to receive(:request)+ .and_return(request)+ allow(inst)+ .to receive(:controller)+ .and_return(controller_instance)+ end+ end+ let(:project) do+ instance_double('Project')+ end+ let(:request) do+ instance_double('ActiveSupport::Request')+ end+ let(:controller_instance) do+ instance_double('ApplicationController')+ end++ it 'adds to the context' do+ # mimicks having two different classes registered for the hook+ allow(OpenProject::Hook)+ .to receive(:call_hook)+ .and_return(%w[response1 response2])++ expect(instance.call_hook(:some_hook_identifier, {}))+ .to eql "response1 response2"++ expect(OpenProject::Hook)+ .to have_received(:call_hook)+ .with(:some_hook_identifier, { project: project,+ controller: controller_instance,+ request: request,+ hook_caller: instance })+ end+ end+ end+enddiff --git a/spec/lib/open_project/hook_spec.rb b/spec/lib/open_project/hook_spec.rbnew file mode 100644index 00000000000..91156e6ee1d--- /dev/null+++ b/spec/lib/open_project/hook_spec.rb@@ -0,0 +1,273 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#+++require 'spec_helper'++describe OpenProject::Hook do+ let(:test_hook_class) do+ Class.new(OpenProject::Hook::ViewListener)+ end+ let(:test_hook1_class) do+ Class.new(test_hook_class) do+ def view_layouts_base_html_head(_context)+ 'Test hook 1 listener.'+ end+ end+ end+ let(:test_hook2_class) do+ Class.new(test_hook_class) do+ def view_layouts_base_html_head(_context)+ 'Test hook 2 listener.'+ end+ end+ end+ let(:test_hook3_class) do+ Class.new(test_hook_class) do+ def view_layouts_base_html_head(context)+ "Context keys: #{context.keys.map(&:to_s).sort.join(', ')}."+ end+ end+ end+ let!(:previous_listener_classes) { described_class.listener_classes.dup }++ before do+ described_class.clear_listeners+ end++ after do+ described_class.clear_listeners+ described_class.instance_variable_set(:@listener_classes, previous_listener_classes)+ end++ describe '#add_listeners' do+ context 'when inheriting from the class' do+ it 'is automatically added' do+ expect(described_class.hook_listeners(:view_layouts_base_html_head))+ .to be_empty++ test_hook1_class++ expect(described_class.hook_listeners(:view_layouts_base_html_head))+ .to match_array([test_hook1_class])+ end+ end++ context 'when explicitly adding' do+ let(:test_class) do+ Class.new do+ include Singleton++ def view_layouts_base_html_head(_context)+ 'Test hook listener.'+ end+ end+ end++ it 'adds listeners' do+ described_class.add_listener(test_class)+ expect(described_class.hook_listeners(:view_layouts_base_html_head))+ .to match_array([test_class])+ end+ end++ context 'when not having the Singleton module included' do+ let(:test_class) do+ Class.new do+ def view_layouts_base_html_head(_context)+ 'Test hook listener.'+ end+ end+ end++ it 'adds listeners' do+ expect { described_class.add_listener(test_class) }+ .to raise_error ArgumentError+ end+ end+ end++ describe '#clear_listeners' do+ before do+ # implicitly adding by class creation+ test_hook1_class+ end++ it 'clears the registered listeners' do+ described_class.clear_listeners+ expect(described_class.hook_listeners(:view_layouts_base_html_head))+ .to be_empty+ end+ end++ describe '#call_hook' do+ context 'with a class registered for the hook' do+ before do+ # implicitly adding by class creation+ test_hook1_class+ end++ it 'calls the registered method' do+ expect(described_class.call_hook(:view_layouts_base_html_head))+ .to match_array test_hook1_class.instance.view_layouts_base_html_head(nil)+ end+ end++ context 'without a class registered for the hook' do+ it 'calls the registered method' do+ expect(described_class.call_hook(:view_layouts_base_html_head))+ .to be_empty+ end+ end++ context 'with multiple listeners' do+ before do+ # implicitly adding by class creation+ test_hook1_class+ test_hook2_class+ end++ it 'calls all registered methods' do+ expect(described_class.call_hook(:view_layouts_base_html_head))+ .to match_array [test_hook1_class.instance.view_layouts_base_html_head(nil),+ test_hook2_class.instance.view_layouts_base_html_head(nil)]+ end+ end++ context 'with a context' do+ let!(:test_hook_context_class) do+ # implicitly adding by class creation+ Class.new(test_hook_class) do+ def view_layouts_base_html_head(context)+ context+ end+ end+ end++ let(:context) { { foo: 1, bar: 'a'} }++ it 'passes the context through' do+ expect(described_class.call_hook(:view_layouts_base_html_head, **context))+ .to match_array [context]+ end+ end++ context 'with a link rendered in the hooked to method' do+ let!(:test_hook_link_class) do+ # implicitly adding by class creation+ Class.new(test_hook_class) do+ def view_layouts_base_html_head(_context)+ link_to('Work packages', controller: '/work_packages')+ end+ end+ end++ it 'renders the link' do+ expect(described_class.call_hook(:view_layouts_base_html_head))+ .to match_array ['<a href="/work_packages">Work packages</a>']+ end+ end++ context 'when called within a controller' do+ let(:test_hook_controller_class) do+ # Also tests that the application controller has the model included+ Class.new(ApplicationController)+ end+ let!(:test_hook_context_class) do+ # implicitly adding by class creation+ Class.new(test_hook_class) do+ def view_layouts_base_html_head(context)+ context+ end+ end+ end+ let(:instance) do+ test_hook_controller_class.new.tap do |inst|+ inst.instance_variable_set(:@project, project)+ allow(inst)+ .to receive(:request)+ .and_return(request)+ end+ end+ let(:project) do+ instance_double('Project')+ end+ let(:request) do+ instance_double('ActiveSupport::Request')+ end++ it 'adds to the context' do+ expect(instance.call_hook(:view_layouts_base_html_head, {}))+ .to match_array [{ project: project, controller: instance, request: request, hook_caller: instance }]+ end+ end+ end++ context 'called within email rendering' do+ let!(:test_hook_link_class) do+ # implicitly adding by class creation+ Class.new(test_hook_class) do+ def view_layouts_base_html_head(_context)+ link_to('Work packages', controller: '/work_packages')+ end+ end+ end+ let(:test_hook_controller_class) do+ # Also tests that the application controller has the model included+ Class.new(ApplicationController)+ end++ let(:user) { FactoryBot.build_stubbed(:user) }+ let(:author) { FactoryBot.build_stubbed(:user) }+ let(:work_package) do+ FactoryBot.build_stubbed(:work_package,+ type: FactoryBot.build_stubbed(:type),+ status: FactoryBot.build_stubbed(:status)).tap do |wp|++ allow(wp)+ .to receive(:reload)+ .and_return(wp)+ end+ end+ let(:journal) { FactoryBot.build_stubbed(:work_package_journal, journable: work_package) }+ let!(:comparison_mail) do+ UserMailer.work_package_added(user, journal, author).deliver_now+ ActionMailer::Base.deliveries.last+ end++ it 'does not_change_the_default_url_for_email_notifications' do+ test_hook_controller_class.new.call_hook(:view_layouts_base_html_head)++ ActionMailer::Base.deliveries.clear+ UserMailer.work_package_added(user, journal, author).deliver_now+ mail2 = ActionMailer::Base.deliveries.last++ assert_equal comparison_mail.text_part.body.encoded, mail2.text_part.body.encoded+ end+ end+enddiff --git a/spec/models/work_package/hooks_spec.rb b/spec/models/work_package/hooks_spec.rbindex 3a71e853461..76095aab107 100644--- a/spec/models/work_package/hooks_spec.rb+++ b/spec/models/work_package/hooks_spec.rb@@ -33,7 +33,7 @@ describe WorkPackage, type: :model doit "calls the create hook" dosubject = "A new work package"- expect(Redmine::Hook).to receive(:call_hook) do |hook, context|+ expect(OpenProject::Hook).to receive(:call_hook) do |hook, context|expect(hook).to eq :work_package_after_createexpect(context[:work_package].subject).to eq subjectend@@ -46,7 +46,7 @@ describe WorkPackage, type: :model dolet!(:work_package) { FactoryBot.create :work_package }it "calls the update hook" do- expect(Redmine::Hook).to receive(:call_hook) do |hook, context|+ expect(OpenProject::Hook).to receive(:call_hook) do |hook, context|expect(hook).to eq :work_package_after_updateexpect(context[:work_package]).to eq work_packageexpect(context[:work_package].journals.last.details[:description].last).to eq "changed description"diff --git a/spec_legacy/functional/application_controller_spec.rb b/spec_legacy/functional/application_controller_spec.rbdeleted file mode 100644index 8926311e28d..00000000000--- a/spec_legacy/functional/application_controller_spec.rb+++ /dev/null@@ -1,39 +0,0 @@-#-- encoding: UTF-8--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2021 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See docs/COPYRIGHT.rdoc for more details.-#++-require_relative '../legacy_spec_helper'-require 'application_controller'--describe ApplicationController, type: :controller do- include Redmine::I18n-- it 'should call hook mixed in' do- assert @controller.respond_to?(:call_hook)- end-enddiff --git a/spec_legacy/unit/lib/redmine/hook_spec.rb b/spec_legacy/unit/lib/redmine/hook_spec.rbdeleted file mode 100644index b689c7a5756..00000000000--- a/spec_legacy/unit/lib/redmine/hook_spec.rb+++ /dev/null@@ -1,182 +0,0 @@-#-- encoding: UTF-8--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2021 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See docs/COPYRIGHT.rdoc for more details.-#++-require_relative '../../../legacy_spec_helper'--describe 'Redmine::Hook::Manager' do # FIXME: naming (RSpec-port)- fixtures :all-- # Some hooks that are manually registered in these tests- class TestHook < Redmine::Hook::ViewListener; end-- class TestHook1 < TestHook- def view_layouts_base_html_head(_context)- 'Test hook 1 listener.'- end- end-- class TestHook2 < TestHook- def view_layouts_base_html_head(_context)- 'Test hook 2 listener.'- end- end-- class TestHook3 < TestHook- def view_layouts_base_html_head(context)- "Context keys: #{context.keys.map(&:to_s).sort.join(', ')}."- end- end-- class TestLinkToHook < TestHook- def view_layouts_base_html_head(_context)- link_to('Issues', controller: '/work_packages')- end- end-- class TestHookHelperController < ActionController::Base- include HookHelper- end-- class TestHookHelperView < ActionView::Base- include HookHelper- end-- Redmine::Hook.clear_listeners-- before do- @hook_module = Redmine::Hook- end-- after do- @hook_module.clear_listeners- end-- it 'should clear_listeners' do- assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size- @hook_module.add_listener(TestHook1)- @hook_module.add_listener(TestHook2)- assert_equal 2, @hook_module.hook_listeners(:view_layouts_base_html_head).size-- @hook_module.clear_listeners- assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size- end-- it 'should add_listener' do- assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size- @hook_module.add_listener(TestHook1)- assert_equal 1, @hook_module.hook_listeners(:view_layouts_base_html_head).size- end-- it 'should call_hook' do- @hook_module.add_listener(TestHook1)- assert_equal ['Test hook 1 listener.'], hook_helper.call_hook(:view_layouts_base_html_head)- end-- it 'should call_hook_with_context' do- @hook_module.add_listener(TestHook3)- assert_equal ['Context keys: bar, controller, foo, hook_caller, project, request.'],- hook_helper.call_hook(:view_layouts_base_html_head, foo: 1, bar: 'a')- end-- it 'should call_hook_with_multiple_listeners' do- @hook_module.add_listener(TestHook1)- @hook_module.add_listener(TestHook2)- assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], hook_helper.call_hook(:view_layouts_base_html_head)- end-- # Context: HookHelper.call_hook default_url- it 'should call_hook_default_url_options' do- @hook_module.add_listener(TestLinkToHook)-- assert_equal ['<a href="/work_packages">Issues</a>'], hook_helper.call_hook(:view_layouts_base_html_head)- end-- # Context: HookHelper.call_hook- it 'should call_hook_with_project_added_to_context' do- @hook_module.add_listener(TestHook3)- assert_match /project/i, hook_helper.call_hook(:view_layouts_base_html_head)[0]- end-- it 'should call_hook_from_controller_with_controller_added_to_context' do- @hook_module.add_listener(TestHook3)- assert_match /controller/i, hook_helper.call_hook(:view_layouts_base_html_head)[0]- end-- it 'should call_hook_from_controller_with_request_added_to_context' do- @hook_module.add_listener(TestHook3)- assert_match /request/i, hook_helper.call_hook(:view_layouts_base_html_head)[0]- end-- it 'should call_hook_from_view_with_project_added_to_context' do- @hook_module.add_listener(TestHook3)- assert_match /project/i, view_hook_helper.call_hook(:view_layouts_base_html_head)- end-- it 'should call_hook_from_view_with_controller_added_to_context' do- @hook_module.add_listener(TestHook3)- assert_match /controller/i, view_hook_helper.call_hook(:view_layouts_base_html_head)- end-- it 'should call_hook_from_view_with_request_added_to_context' do- @hook_module.add_listener(TestHook3)- assert_match /request/i, view_hook_helper.call_hook(:view_layouts_base_html_head)- end-- it 'should call_hook_from_view_should_join_responses_with_a_space' do- @hook_module.add_listener(TestHook1)- @hook_module.add_listener(TestHook2)- assert_equal 'Test hook 1 listener. Test hook 2 listener.',- view_hook_helper.call_hook(:view_layouts_base_html_head)- end-- it 'should call_hook_should_not_change_the_default_url_for_email_notifications' do- user = User.find(1)- issue = FactoryBot.create(:work_package)-- UserMailer.work_package_added(user, issue.journals.first, user).deliver_now- mail = ActionMailer::Base.deliveries.last-- @hook_module.add_listener(TestLinkToHook)- hook_helper.call_hook(:view_layouts_base_html_head)-- ActionMailer::Base.deliveries.clear- UserMailer.work_package_added(user, issue.journals.first, user).deliver_now- mail2 = ActionMailer::Base.deliveries.last-- assert_equal mail.text_part.body.encoded, mail2.text_part.body.encoded- end-- def hook_helper- @hook_helper ||= TestHookHelperController.new- end-- def view_hook_helper- @view_hook_helper ||= TestHookHelperView.new(ActionView::LookupContext.new(Rails.root.to_s + '/app/views'), {}, nil)- end-enddiff --git a/spec_legacy/unit/lib/redmine/i18n_spec.rb b/spec_legacy/unit/lib/redmine/i18n_spec.rbindex 8092f7b9c26..ef693a235bc 100644--- a/spec_legacy/unit/lib/redmine/i18n_spec.rb+++ b/spec_legacy/unit/lib/redmine/i18n_spec.rb@@ -33,10 +33,6 @@ describe Redmine::I18n doinclude Redmine::I18ninclude ActionView::Helpers::NumberHelper- before do- @hook_module = Redmine::Hook- end-it 'should date and time for each language' doSetting.date_format = ''valid_languages.each do |lang|