mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
692dbbf793
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8805 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
45 lines
1.3 KiB
Ruby
45 lines
1.3 KiB
Ruby
require 'abstract_unit'
|
|
|
|
class CustomHandler < ActionView::TemplateHandler
|
|
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
|
|
ActionView::Base.register_template_handler :foo2, CustomHandler
|
|
@view = ActionView::Base.new
|
|
end
|
|
|
|
def test_custom_render
|
|
template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo")
|
|
|
|
result = @view.render_template(template)
|
|
assert_equal(
|
|
[ "hello <%= one %>", { :one => "two" }, @view ],
|
|
result )
|
|
end
|
|
|
|
def test_custom_render2
|
|
template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo2")
|
|
result = @view.render_template(template)
|
|
assert_equal(
|
|
[ "hello <%= one %>", { :one => "two" }, @view ],
|
|
result )
|
|
end
|
|
|
|
def test_unhandled_extension
|
|
# uses the ERb handler by default if the extension isn't recognized
|
|
template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "bar")
|
|
result = @view.render_template(template)
|
|
assert_equal "hello two", result
|
|
end
|
|
end
|