aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/custom_handler_test.rb
blob: cdde00cccc817ec972b9eb99c646d7336604959c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'abstract_unit'

class CustomHandler < ActionView::TemplateHandler
  def initialize( view )
    @view = view
  end

  def render( template )
    [ template.source,
      template.locals,
      @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