From efd26d1dd30e79b3a5211f27b6bb7b8ee5258dea Mon Sep 17 00:00:00 2001 From: Jesse Storimer Date: Thu, 26 Aug 2010 22:18:35 -0400 Subject: [PATCH] Ensure that inherited helper_methods are available after calling clear_helpers --- actionpack/lib/abstract_controller/helpers.rb | 9 +++++++ actionpack/test/controller/helper_test.rb | 31 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb index a0ce121..65b6b14 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 @@ -49,6 +52,8 @@ module AbstractController controller.send(%(#{meth}), *args, &blk) end ruby_eval + + _helper_methods << meth end end @@ -98,7 +103,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 4f8ff41..9093fa9 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} -- 1.7.2.2