public
Created

  • Download Gist
skip-helper-all.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
From eb3a2f14004f391466239ec27a0e74822ebf83cb 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/action_controller/base.rb | 2 +-
actionpack/lib/action_controller/metal/helpers.rb | 6 ++++++
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/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/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb
index e0bc473..c51b6a6 100644
--- a/actionpack/lib/action_controller/metal/helpers.rb
+++ b/actionpack/lib/action_controller/metal/helpers.rb
@@ -54,6 +54,8 @@ module ActionController
included do
config_accessor :helpers_path
+ config_accessor :dont_include_all_helpers
+
self.helpers_path ||= []
end
@@ -86,6 +88,10 @@ module ActionController
@helper_proxy ||= ActionView::Base.new.extend(_helpers)
end
+ def skip_helper_all
+ self.dont_include_all_helpers = true
+ end
+
private
# Overwrite modules_for_helpers to accept :all as argument, which loads
# all helpers in helpers_dir.
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.