From 730af4896358d9125dbd7b8384d66460ae839a45 Mon Sep 17 00:00:00 2001 From: Jesse Storimer Date: Thu, 26 Aug 2010 22:18:35 -0400 Subject: Ensure that inherited helper_methods are available after calling clear_helpers [#5348 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/abstract_controller/helpers.rb | 12 ++++++++++- actionpack/test/controller/helper_test.rb | 31 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb index a0ce121ade..20f8601a8e 100644 --- a/actionpack/lib/abstract_controller/helpers.rb +++ b/actionpack/lib/abstract_controller/helpers.rb @@ -9,6 +9,9 @@ module AbstractController included do class_attribute :_helpers self._helpers = Module.new + + class_attribute :_helper_methods + self._helper_methods = Array.new end module ClassMethods @@ -43,7 +46,10 @@ module AbstractController # * method[, method] - A name or names of a method on the controller # to be made available on the view. def helper_method(*meths) - meths.flatten.each do |meth| + meths.flatten! + self._helper_methods += meths + + meths.each do |meth| _helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 def #{meth}(*args, &blk) controller.send(%(#{meth}), *args, &blk) @@ -98,7 +104,11 @@ module AbstractController # Clears up all existing helpers in this class, only keeping the helper # with the same name as this class. def clear_helpers + inherited_helper_methods = _helper_methods self._helpers = Module.new + self._helper_methods = Array.new + + inherited_helper_methods.each { |meth| helper_method meth } default_helper_module! unless anonymous? end diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 4f8ff4140f..9093fa9e17 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -25,8 +25,27 @@ class AllHelpersController < ActionController::Base helper :all end +module ImpressiveLibrary + extend ActiveSupport::Concern + included do + helper_method :useful_function + end + + def useful_function() end +end + +ActionController::Base.send :include, ImpressiveLibrary + class JustMeController < ActionController::Base clear_helpers + + def flash + render :inline => "

<%= notice %>

" + end + + def lib + render :inline => '<%= useful_function %>' + end end class MeTooController < JustMeController @@ -104,6 +123,18 @@ class HelperTest < ActiveSupport::TestCase assert_equal [MeTooHelper, JustMeHelper], MeTooController._helpers.ancestors.reject(&:anonymous?) end + def test_base_helper_methods_after_clear_helpers + assert_nothing_raised do + call_controller(JustMeController, "flash") + end + end + + def test_lib_helper_methods_after_clear_helpers + assert_nothing_raised do + call_controller(JustMeController, "lib") + end + end + def test_all_helpers methods = AllHelpersController._helpers.instance_methods.map {|m| m.to_s} -- cgit v1.2.3