2008-01-05 08:32:06 -05:00
|
|
|
require 'abstract_unit'
|
2005-02-19 12:22:37 -05:00
|
|
|
|
2008-01-10 23:45:06 -05:00
|
|
|
class CustomHandler < ActionView::TemplateHandler
|
2005-02-19 12:22:37 -05:00
|
|
|
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
|
2008-02-05 23:26:40 -05:00
|
|
|
template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo")
|
|
|
|
|
|
|
|
result = @view.render_template(template)
|
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
|
2008-02-05 23:26:40 -05:00
|
|
|
template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo2")
|
|
|
|
result = @view.render_template(template)
|
2006-03-26 16:50:22 -05:00
|
|
|
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
|
2008-02-05 23:26:40 -05:00
|
|
|
template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "bar")
|
|
|
|
result = @view.render_template(template)
|
2005-02-19 12:22:37 -05:00
|
|
|
assert_equal "hello two", result
|
|
|
|
end
|
|
|
|
end
|