Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/trunk/actionpack/test/controller/custom_handler_test.rb

Revision 8981, 1.3 kB (checked in by pratik, 9 months ago)

Moved template handlers related code from ActionView::Base to ActionView::Template

Line 
1 require 'abstract_unit'
2
3 class CustomHandler < ActionView::TemplateHandler
4   def initialize( view )
5     @view = view
6   end
7
8   def render( template )
9     [ template.source,
10       template.locals,
11       @view ]
12   end
13 end
14
15 class CustomHandlerTest < Test::Unit::TestCase
16   def setup
17     ActionView::Template.register_template_handler "foo", CustomHandler
18     ActionView::Template.register_template_handler :foo2, CustomHandler
19     @view = ActionView::Base.new
20   end
21
22   def test_custom_render
23     template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo")
24
25     result = @view.render_template(template)
26     assert_equal(
27       [ "hello <%= one %>", { :one => "two" }, @view ],
28       result )
29   end
30
31   def test_custom_render2
32     template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo2")
33     result = @view.render_template(template)
34     assert_equal(
35       [ "hello <%= one %>", { :one => "two" }, @view ],
36       result )
37   end
38
39   def test_unhandled_extension
40     # uses the ERb handler by default if the extension isn't recognized
41     template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "bar")
42     result = @view.render_template(template)
43     assert_equal "hello two", result
44   end
45 end
Note: See TracBrowser for help on using the browser.