2009-09-19 13:10:41 -04:00
|
|
|
require 'abstract_unit'
|
2009-03-03 19:42:20 -05:00
|
|
|
|
2010-07-07 15:03:01 -04:00
|
|
|
ActionController::Base.helpers_path = File.expand_path('../../fixtures/helpers', __FILE__)
|
2009-10-21 12:42:58 -04:00
|
|
|
|
2009-03-03 19:42:20 -05:00
|
|
|
module AbstractController
|
|
|
|
module Testing
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-03-03 19:42:20 -05:00
|
|
|
class ControllerWithHelpers < AbstractController::Base
|
2009-12-20 20:15:31 -05:00
|
|
|
include AbstractController::Rendering
|
2009-05-11 20:07:05 -04:00
|
|
|
include Helpers
|
2009-10-18 20:52:36 -04:00
|
|
|
|
2009-10-21 12:42:58 -04:00
|
|
|
def with_module
|
|
|
|
render :inline => "Module <%= included_method %>"
|
2009-03-20 19:50:51 -04:00
|
|
|
end
|
2009-03-03 19:42:20 -05:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-03-03 19:42:20 -05:00
|
|
|
module HelperyTest
|
|
|
|
def included_method
|
|
|
|
"Included"
|
|
|
|
end
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2009-10-21 12:42:58 -04:00
|
|
|
class AbstractHelpers < ControllerWithHelpers
|
2009-03-03 19:42:20 -05:00
|
|
|
helper(HelperyTest) do
|
|
|
|
def helpery_test
|
|
|
|
"World"
|
|
|
|
end
|
|
|
|
end
|
2009-10-21 12:42:58 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2010-08-26 15:03:10 -04:00
|
|
|
class ::HelperyTestController < AbstractHelpers
|
|
|
|
clear_helpers
|
|
|
|
end
|
|
|
|
|
2009-10-21 12:42:58 -04:00
|
|
|
class AbstractHelpersBlock < ControllerWithHelpers
|
|
|
|
helper do
|
2009-11-04 17:49:29 -05:00
|
|
|
include ::AbstractController::Testing::HelperyTest
|
2009-03-03 19:42:20 -05:00
|
|
|
end
|
|
|
|
end
|
2009-10-21 12:42:58 -04:00
|
|
|
|
2009-03-03 19:42:20 -05:00
|
|
|
class TestHelpers < ActiveSupport::TestCase
|
2009-10-21 12:42:58 -04:00
|
|
|
def setup
|
|
|
|
@controller = AbstractHelpers.new
|
2009-03-03 19:42:20 -05:00
|
|
|
end
|
2009-10-21 12:42:58 -04:00
|
|
|
|
|
|
|
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
|
2009-03-03 19:42:20 -05:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-08-26 15:03:10 -04:00
|
|
|
class ClearHelpersTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@controller = HelperyTestController.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_clears_up_previous_helpers
|
|
|
|
@controller.process(:with_symbol)
|
|
|
|
assert_equal "I respond to bare_a: false", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_includes_controller_default_helper
|
|
|
|
@controller.process(:with_block)
|
|
|
|
assert_equal "Hello Default", @controller.response_body
|
|
|
|
end
|
|
|
|
end
|
2009-03-03 19:42:20 -05:00
|
|
|
end
|
2009-08-06 17:48:48 -04:00
|
|
|
end
|