Project

General

Profile

Actions

Defect #28133

open

Controller patch causes Helper Patch down

Added by Haihan Ji almost 7 years ago. Updated over 5 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

Create two plugins, one named 'test_001', another is 'test_002'.

test_001

# init.rb
Rails.configuration.to_prepare do
  require 'test_issues_controller_patch'
end

Redmine::Plugin.register :test_001 do
  name 'Test 001 plugin'
  author 'Author name'
  description 'This is a plugin for Redmine'
  version '0.0.1'
  url 'http://example.com/path/to/plugin'
  author_url 'http://example.com/about'
end

# lib/test_issues_controller_patch.rb
module TestIssuesControllerPatch
  extend ActiveSupport::Concern
  included do
  end
end

unless IssuesController.included_modules.include?(TestIssuesControllerPatch)
  IssuesController.send :include, TestIssuesControllerPatch
end

test_002

# init.rb
Rails.configuration.to_prepare do
  require 'test_hooks'
  require 'test_issues_helper_patch'
end

# Rails.configuration.to_prepare
Redmine::Plugin.register :test_002 do
  name 'Test 002 plugin'
  author 'Author name'
  description 'This is a plugin for Redmine'
  version '0.0.1'
  url 'http://example.com/path/to/plugin'
  author_url 'http://example.com/about'
end

# lib/test_issues_helper_patch.rb
module TestIssuesHelperPatch
  extend ActiveSupport::Concern
  included do
  end

  def test_hello
    'hello world'
  end
end

unless IssuesHelper.included_modules.include?(TestIssuesHelperPatch)
  IssuesHelper.send :include, TestIssuesHelperPatch
end

# lib/test_hooks.rb
class TestHooks < Redmine::Hook::ViewListener
  def view_issues_show_details_bottom(context={})
    context[:hook_caller].instance_eval do
        render(:partial => 'test/hello_world')
    end
  end
end

# app/views/test/_hello_world.html.rb
<%= test_hello %>

If everything is OK, 'hello world' should be displayed in issue detail page.
BUT I see:

ActionView::Template::Error (undefined local variable or method `test_hello' for #<#<Class:0x007fca71f0bd90>:0x007fca71f00760>):
    1: <%= test_hello %>
  plugins/test_002/app/views/test/_hello_world.html.erb:1:in `_plugins_test_____app_views_test__hello_world_html_erb__3192427753573044533_70253770942940'
  plugins/test_002/lib/test_hooks.rb:4:in `block in view_issues_show_details_bottom'
  plugins/test_002/lib/test_hooks.rb:3:in `instance_eval'
  plugins/test_002/lib/test_hooks.rb:3:in `view_issues_show_details_bottom'
  lib/redmine/hook.rb:61:in `block (2 levels) in call_hook'
  lib/redmine/hook.rb:61:in `each'
  lib/redmine/hook.rb:61:in `block in call_hook'
  lib/redmine/hook.rb:58:in `tap'
  lib/redmine/hook.rb:58:in `call_hook'
  lib/redmine/hook.rb:96:in `call_hook'
  app/views/issues/show.html.erb:70:in `_app_views_issues_show_html_erb__1203365146500478953_70253735647440'
  app/controllers/issues_controller.rb:111:in `block (2 levels) in show'
  app/controllers/issues_controller.rb:104:in `show'
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'

If I disable test_001, or rename test_002 to test_000,it's work.
It seems that controller patch make helper patch failed.

Actions

Also available in: Atom PDF