2005-02-19 12:22:37 -05:00
|
|
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
|
|
|
|
|
|
|
class CustomHandler
|
|
|
|
def initialize( view )
|
|
|
|
@view = view
|
|
|
|
end
|
|
|
|
|
|
|
|
def render( template, local_assigns )
|
|
|
|
[ template,
|
|
|
|
local_assigns,
|
|
|
|
@view ]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class CustomHandlerTest < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
ActionView::Base.register_template_handler "foo", CustomHandler
|
2006-03-26 16:50:22 -05:00
|
|
|
ActionView::Base.register_template_handler :foo2, CustomHandler
|
2005-02-19 12:22:37 -05:00
|
|
|
@view = ActionView::Base.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_custom_render
|
2005-09-27 12:45:39 -04:00
|
|
|
result = @view.render_template( "foo", "hello <%= one %>", nil, :one => "two" )
|
2005-02-19 12:22:37 -05:00
|
|
|
assert_equal(
|
2005-09-27 12:45:39 -04:00
|
|
|
[ "hello <%= one %>", { :one => "two" }, @view ],
|
2005-02-19 12:22:37 -05:00
|
|
|
result )
|
|
|
|
end
|
|
|
|
|
2006-03-26 16:50:22 -05:00
|
|
|
def test_custom_render2
|
|
|
|
result = @view.render_template( "foo2", "hello <%= one %>", nil, :one => "two" )
|
|
|
|
assert_equal(
|
|
|
|
[ "hello <%= one %>", { :one => "two" }, @view ],
|
|
|
|
result )
|
|
|
|
end
|
|
|
|
|
2005-02-19 12:22:37 -05:00
|
|
|
def test_unhandled_extension
|
|
|
|
# uses the ERb handler by default if the extension isn't recognized
|
2005-09-27 12:45:39 -04:00
|
|
|
result = @view.render_template( "bar", "hello <%= one %>", nil, :one => "two" )
|
2005-02-19 12:22:37 -05:00
|
|
|
assert_equal "hello two", result
|
|
|
|
end
|
|
|
|
end
|