Skip to content

Instantly share code, notes, and snippets.

@jstorimer
Created August 25, 2010 17:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jstorimer/549883 to your computer and use it in GitHub Desktop.
From 14795406d9c3ec5cc20d7db1ef7e2d033685098c Mon Sep 17 00:00:00 2001
From: Jesse Storimer <jstorimer@gmail.com>
Date: Wed, 25 Aug 2010 13:05:39 -0400
Subject: [PATCH] Optionally disable `helper :all` in subclasses of AC::Base
---
actionpack/lib/abstract_controller/helpers.rb | 6 ++++++
actionpack/lib/action_controller/base.rb | 2 +-
actionpack/test/controller/helper_test.rb | 16 ++++++++++++++++
actionpack/test/fixtures/helpers/just_me_helper.rb | 3 +++
4 files changed, 26 insertions(+), 1 deletions(-)
create mode 100644 actionpack/test/fixtures/helpers/just_me_helper.rb
diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb
index 4374b43..ae2110e 100644
--- a/actionpack/lib/abstract_controller/helpers.rb
+++ b/actionpack/lib/abstract_controller/helpers.rb
@@ -9,6 +9,8 @@ module AbstractController
included do
class_attribute :_helpers
self._helpers = Module.new
+
+ cattr_accessor :dont_include_all_helpers
end
module ClassMethods
@@ -95,6 +97,10 @@ module AbstractController
_helpers.module_eval(&block) if block_given?
end
+ def skip_helper_all
+ self.dont_include_all_helpers = true
+ end
+
private
# Makes all the (instance) methods in the helper module available to templates
# rendered through this controller.
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 9dfffce..21eac8e 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -60,7 +60,7 @@ module ActionController
def self.inherited(klass)
super
- klass.helper :all
+ klass.helper(:all) unless klass.dont_include_all_helpers
end
ActiveSupport.run_load_hooks(:action_controller, self)
diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb
index ad66f13..107427f 100644
--- a/actionpack/test/controller/helper_test.rb
+++ b/actionpack/test/controller/helper_test.rb
@@ -25,6 +25,14 @@ class AllHelpersController < ActionController::Base
helper :all
end
+class NoHelpersController < ActionController::Base
+ skip_helper_all
+end
+
+class JustMeController < ActionController::Base
+ skip_helper_all
+end
+
module LocalAbcHelper
def a() end
def b() end
@@ -72,6 +80,14 @@ class HelperTest < ActiveSupport::TestCase
request = ActionController::TestRequest.new
klass.action(action).call(request.env)
end
+
+ def test_skip_helper_all
+ assert [], NoHelpersController._helpers.ancestors.reject(&:anonymous?)
+ end
+
+ def test_skip_helper_all_complicated
+ assert_equal [JustMeHelper], JustMeController._helpers.ancestors.reject(&:anonymous?)
+ end
def test_helper_for_nested_controller
assert_equal 'hello: Iz guuut!',
diff --git a/actionpack/test/fixtures/helpers/just_me_helper.rb b/actionpack/test/fixtures/helpers/just_me_helper.rb
new file mode 100644
index 0000000..b140a7b
--- /dev/null
+++ b/actionpack/test/fixtures/helpers/just_me_helper.rb
@@ -0,0 +1,3 @@
+module JustMeHelper
+ def me() "mine!" end
+end
\ No newline at end of file
--
1.7.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment