aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/helper_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/controller/helper_test.rb')
-rw-r--r--actionpack/test/controller/helper_test.rb68
1 files changed, 50 insertions, 18 deletions
diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb
index 9b9657929f..9f0670ffdf 100644
--- a/actionpack/test/controller/helper_test.rb
+++ b/actionpack/test/controller/helper_test.rb
@@ -25,6 +25,32 @@ 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 => "<h1><%= notice %></h1>"
+ end
+
+ def lib
+ render :inline => '<%= useful_function %>'
+ end
+end
+
+class MeTooController < JustMeController
+end
+
module LocalAbcHelper
def a() end
def b() end
@@ -50,7 +76,7 @@ class HelperTest < ActiveSupport::TestCase
# Set default test helper.
self.test_helper = LocalAbcHelper
end
-
+
def test_deprecated_helper
assert_equal expected_helper_methods, missing_methods
assert_nothing_raised { @controller_class.helper TestHelper }
@@ -70,28 +96,45 @@ class HelperTest < ActiveSupport::TestCase
def call_controller(klass, action)
request = ActionController::TestRequest.new
- klass.action(action).call(request.env)
+ klass.action(action).call(request.env)
end
def test_helper_for_nested_controller
- assert_equal 'hello: Iz guuut!',
+ assert_equal 'hello: Iz guuut!',
call_controller(Fun::GamesController, "render_hello_world").last.body
# request = ActionController::TestRequest.new
- #
+ #
# resp = Fun::GamesController.action(:render_hello_world).call(request.env)
# assert_equal 'hello: Iz guuut!', resp.last.body
end
def test_helper_for_acronym_controller
assert_equal "test: baz", call_controller(Fun::PdfController, "test").last.body
- #
+ #
# request = ActionController::TestRequest.new
# response = ActionController::TestResponse.new
# request.action = 'test'
- #
+ #
# assert_equal 'test: baz', Fun::PdfController.process(request, response).body
end
+ def test_default_helpers_only
+ assert_equal [JustMeHelper], JustMeController._helpers.ancestors.reject(&:anonymous?)
+ 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}
@@ -135,17 +178,6 @@ class HelperTest < ActiveSupport::TestCase
assert methods.include?('foobar')
end
- def test_deprecation
- assert_deprecated do
- ActionController::Base.helpers_dir = "some/foo/bar"
- end
- assert_deprecated do
- assert_equal ["some/foo/bar"], ActionController::Base.helpers_dir
- end
- ensure
- ActionController::Base.helpers_path = File.expand_path('../../fixtures/helpers', __FILE__)
- end
-
private
def expected_helper_methods
TestHelper.instance_methods.map {|m| m.to_s }
@@ -192,7 +224,7 @@ class IsolatedHelpersTest < ActiveSupport::TestCase
def call_controller(klass, action)
request = ActionController::TestRequest.new
- klass.action(action).call(request.env)
+ klass.action(action).call(request.env)
end
def setup