aboutsummaryrefslogblamecommitdiffstats
path: root/actionpack/test/controller/custom_handler_test.rb
blob: ac484ae17eee8b6a749855ae20db74d0f30b51a1 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                       
 
                                                 



                        


                        





                                              

                                                                       



                                
                                                                                                  

                                            
                 
                                                       


              
                         
                                                                                                   
                                            




                                                       

                                                                       
                                                                                                  
                                            


                                    
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::Template.register_template_handler "foo", CustomHandler
    ActionView::Template.register_template_handler :foo2, CustomHandler
    @view = ActionView::Base.new
  end

  def test_custom_render
    template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "foo")

    result = @view.render_template(template)
    assert_equal(
      [ "hello <%= one %>", { :one => "two" }, @view ],
      result )
  end

  def test_custom_render2
    template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "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::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "bar")
    result = @view.render_template(template)
    assert_equal "hello two", result
  end
end