mirror of https://github.com/rails/rails
Move some of helper tests to AbstractController.
This commit is contained in:
parent
43d5504f0a
commit
2d514e5352
|
@ -1,19 +1,17 @@
|
|||
require 'abstract_unit'
|
||||
|
||||
ActionController::Base.helpers_dir = File.dirname(__FILE__) + '/../fixtures/helpers'
|
||||
|
||||
module AbstractController
|
||||
module Testing
|
||||
|
||||
class ControllerWithHelpers < AbstractController::Base
|
||||
include AbstractController::RenderingController
|
||||
include Helpers
|
||||
|
||||
def _prefix() end
|
||||
|
||||
def render(string)
|
||||
super(:_template_name => string)
|
||||
def with_module
|
||||
render :inline => "Module <%= included_method %>"
|
||||
end
|
||||
|
||||
append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views"))
|
||||
end
|
||||
|
||||
module HelperyTest
|
||||
|
@ -22,25 +20,62 @@ module AbstractController
|
|||
end
|
||||
end
|
||||
|
||||
class MyHelpers1 < ControllerWithHelpers
|
||||
class AbstractHelpers < ControllerWithHelpers
|
||||
helper(HelperyTest) do
|
||||
def helpery_test
|
||||
"World"
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
render "helper_test.erb"
|
||||
|
||||
helper :abc
|
||||
|
||||
def with_block
|
||||
render :inline => "Hello <%= helpery_test %>"
|
||||
end
|
||||
|
||||
def with_symbol
|
||||
render :inline => "I respond to bare_a: <%= respond_to?(:bare_a) %>"
|
||||
end
|
||||
end
|
||||
|
||||
class TestHelpers < ActiveSupport::TestCase
|
||||
def test_helpers
|
||||
controller = MyHelpers1.new
|
||||
controller.process(:index)
|
||||
assert_equal "Hello World : Included", controller.response_body
|
||||
|
||||
class AbstractHelpersBlock < ControllerWithHelpers
|
||||
helper do
|
||||
include HelperyTest
|
||||
end
|
||||
end
|
||||
|
||||
class TestHelpers < ActiveSupport::TestCase
|
||||
|
||||
def setup
|
||||
@controller = AbstractHelpers.new
|
||||
end
|
||||
|
||||
def test_helpers_with_block
|
||||
@controller.process(:with_block)
|
||||
assert_equal "Hello World", @controller.response_body
|
||||
end
|
||||
|
||||
def test_helpers_with_module
|
||||
@controller.process(:with_module)
|
||||
assert_equal "Module Included", @controller.response_body
|
||||
end
|
||||
|
||||
def test_helpers_with_symbol
|
||||
@controller.process(:with_symbol)
|
||||
assert_equal "I respond to bare_a: true", @controller.response_body
|
||||
end
|
||||
|
||||
def test_declare_missing_helper
|
||||
assert_raise(MissingSourceFile) { AbstractHelpers.helper :missing }
|
||||
end
|
||||
|
||||
def test_helpers_with_module_through_block
|
||||
@controller = AbstractHelpersBlock.new
|
||||
@controller.process(:with_module)
|
||||
assert_equal "Module Included", @controller.response_body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,40 +57,6 @@ class HelperTest < Test::Unit::TestCase
|
|||
assert_equal [], missing_methods
|
||||
end
|
||||
|
||||
def test_declare_helper
|
||||
require 'abc_helper'
|
||||
self.test_helper = AbcHelper
|
||||
assert_equal expected_helper_methods, missing_methods
|
||||
assert_nothing_raised { @controller_class.helper :abc }
|
||||
assert_equal [], missing_methods
|
||||
end
|
||||
|
||||
def test_declare_missing_helper
|
||||
assert_equal expected_helper_methods, missing_methods
|
||||
assert_raise(MissingSourceFile) { @controller_class.helper :missing }
|
||||
end
|
||||
|
||||
def test_declare_missing_file_from_helper
|
||||
require 'broken_helper'
|
||||
rescue LoadError => e
|
||||
assert_nil(/\bbroken_helper\b/.match(e.to_s)[1])
|
||||
end
|
||||
|
||||
def test_helper_block
|
||||
assert_nothing_raised {
|
||||
@controller_class.helper { def block_helper_method; end }
|
||||
}
|
||||
assert master_helper_methods.include?('block_helper_method')
|
||||
end
|
||||
|
||||
def test_helper_block_include
|
||||
assert_equal expected_helper_methods, missing_methods
|
||||
assert_nothing_raised {
|
||||
@controller_class.helper { include HelperTest::TestHelper }
|
||||
}
|
||||
assert [], missing_methods
|
||||
end
|
||||
|
||||
def test_helper_method
|
||||
assert_nothing_raised { @controller_class.helper_method :delegate_method }
|
||||
assert master_helper_methods.include?('delegate_method')
|
||||
|
|
Loading…
Reference in New Issue