Fix/hook service to openproject (#9214)

* move specs from legacy

* move Hook into OpenProject namespace

* replace class variables
pull/9217/head
ulferts 4 years ago committed by GitHub
parent 71b330ea80
commit 5cb227796c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/helpers/hook_helper.rb
  2. 4
      app/models/changeset.rb
  3. 4
      app/models/work_package/hooks.rb
  4. 2
      lib/open_project.rb
  5. 31
      lib/open_project/hook.rb
  6. 2
      lib/open_project/hooks/view_account_login_auth_provider.rb
  7. 2
      lib/open_project/hooks/view_account_login_bottom.rb
  8. 2
      modules/auth_plugins/lib/open_project/auth_plugins/hooks.rb
  9. 2
      modules/backlogs/lib/open_project/backlogs/hooks.rb
  10. 2
      modules/backlogs/lib/open_project/backlogs/hooks/user_settings_hook.rb
  11. 2
      modules/bim/lib/open_project/bim/hooks.rb
  12. 2
      modules/budgets/lib/budgets/hooks/work_package_hook.rb
  13. 2
      modules/xls_export/lib/open_project/xls_export/hooks/cost_report_hook.rb
  14. 2
      modules/xls_export/lib/open_project/xls_export/hooks/work_package_hook.rb
  15. 2
      spec/controllers/account_controller_spec.rb
  16. 117
      spec/helpers/hook_helper_spec.rb
  17. 273
      spec/lib/open_project/hook_spec.rb
  18. 4
      spec/models/work_package/hooks_spec.rb
  19. 39
      spec_legacy/functional/application_controller_spec.rb
  20. 182
      spec_legacy/unit/lib/redmine/hook_spec.rb
  21. 4
      spec_legacy/unit/lib/redmine/i18n_spec.rb

@ -22,12 +22,12 @@ module HookHelper
def 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))
else
default_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_safe
end
end
end

@ -241,8 +241,8 @@ class Changeset < ApplicationRecord
unless Setting.commit_fix_done_ratio.blank?
work_package.done_ratio = Setting.commit_fix_done_ratio.to_i
end
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) && logger
logger.warn("Work package ##{work_package.id} could not be saved by changeset #{id}: #{work_package.errors.full_messages}")
end

@ -39,12 +39,12 @@ module WorkPackage::Hooks
def call_after_create_hook
context = { work_package: self }
Redmine::Hook.call_hook :work_package_after_create, context
OpenProject::Hook.call_hook :work_package_after_create, context
end
def call_after_update_hook
context = { work_package: self }
Redmine::Hook.call_hook :work_package_after_update, context
OpenProject::Hook.call_hook :work_package_after_update, context
end
end

@ -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'

@ -28,42 +28,43 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
module Redmine
module OpenProject
module 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 << klass
clear_listeners_instances
end
# 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_instances
end
# 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 listener
def self.inherited(child)
Redmine::Hook.add_listener(child)
OpenProject::Hook.add_listener(child)
super
end
end
@ -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
#

@ -30,7 +30,7 @@ module OpenProject
module Hooks
##
# Hook called in the login forms which displays the different auth providers
class ViewAccountLoginAuthProvider < Redmine::Hook::ViewListener
class ViewAccountLoginAuthProvider < OpenProject::Hook::ViewListener
render_on :view_account_login_auth_provider,
partial: 'hooks/login/auth_provider'
end

@ -28,7 +28,7 @@
module OpenProject
module Hooks
class ViewAccountLoginBottom < Redmine::Hook::ViewListener
class ViewAccountLoginBottom < OpenProject::Hook::ViewListener
render_on :view_account_login_bottom, partial: 'announcements/show'
end
end

@ -29,7 +29,7 @@
#++
module OpenProject::AuthPlugins
class Hooks < Redmine::Hook::ViewListener
class Hooks < OpenProject::Hook::ViewListener
render_on :view_account_login_auth_provider, partial: 'hooks/login/providers'
render_on :view_layouts_base_html_head, partial: 'hooks/login/providers_css'
end

@ -27,7 +27,7 @@
#++
module OpenProject::Backlogs::Hooks
class LayoutHook < Redmine::Hook::ViewListener
class LayoutHook < OpenProject::Hook::ViewListener
include RbCommonHelper
def view_versions_show_bottom(context = {})

@ -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:

@ -27,7 +27,7 @@
#+
module OpenProject::Bim::Hooks
class Hook < Redmine::Hook::Listener
class Hook < OpenProject::Hook::Listener
include ActionView::Helpers::TagHelper
include ActionView::Context
include WorkPackagesHelper

@ -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:

@ -1,5 +1,5 @@
module OpenProject::XlsExport::Hooks
class CostReportHook < Redmine::Hook::ViewListener
class CostReportHook < OpenProject::Hook::ViewListener
render_on :view_cost_report_toolbar, partial: 'hooks/xls_report/view_cost_report_toolbar'
end
end

@ -1,5 +1,5 @@
module OpenProject::XlsExport::Hooks
class WorkPackageHook < Redmine::Hook::ViewListener
class WorkPackageHook < OpenProject::Hook::ViewListener
def link_to_xls(context, label, options = {})
url = {
project_id: context[:project],

@ -29,7 +29,7 @@
require 'spec_helper'
describe AccountController, type: :controller do
class UserHook < Redmine::Hook::ViewListener
class UserHook < OpenProject::Hook::ViewListener
attr_reader :registered_user, :first_login_user
def user_registered(context)

@ -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
end

@ -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
end

@ -33,7 +33,7 @@ describe WorkPackage, type: :model do
it "calls the create hook" do
subject = "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_create
expect(context[:work_package].subject).to eq subject
end
@ -46,7 +46,7 @@ describe WorkPackage, type: :model do
let!(: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_update
expect(context[:work_package]).to eq work_package
expect(context[:work_package].journals.last.details[:description].last).to eq "changed description"

@ -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
end

@ -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
end

@ -33,10 +33,6 @@ describe Redmine::I18n do
include Redmine::I18n
include ActionView::Helpers::NumberHelper
before do
@hook_module = Redmine::Hook
end
it 'should date and time for each language' do
Setting.date_format = ''
valid_languages.each do |lang|

Loading…
Cancel
Save