Sha256: 0dd6d14419a8628c12b32dba9aa49fcaca9d846942b63df1a85e4ef5df1567f4

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

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

Version data entries

11 entries across 11 versions & 5 rubygems

Version Path
radiant-0.7.2 vendor/rails/actionpack/test/controller/custom_handler_test.rb
vibes-bj-1.2.2 spec/rails_root/vendor/rails/actionpack/test/controller/custom_handler_test.rb
vibes-bj-1.2.1 spec/rails_root/vendor/rails/actionpack/test/controller/custom_handler_test.rb
actionpack-2.1.0 test/controller/custom_handler_test.rb
actionpack-2.1.1 test/controller/custom_handler_test.rb
actionpack-2.1.2 test/controller/custom_handler_test.rb
antfarm-0.3.0 rails/vendor/rails/actionpack/test/controller/custom_handler_test.rb
antfarm-0.4.0 rails/vendor/rails/actionpack/test/controller/custom_handler_test.rb
eactionpack-2.1.2 test/controller/custom_handler_test.rb
radiant-0.7.0 vendor/rails/actionpack/test/controller/custom_handler_test.rb
radiant-0.7.1 vendor/rails/actionpack/test/controller/custom_handler_test.rb