Namespace
Methods
N
R
S
T
W
Constants
ERBHandler = ActionView::Template::Handlers::ERB.new
 
Instance Public methods
new_template(body = "<%= hello %>", details = { format: :html })
# File actionview/test/template/template_test.rb, line 54
def new_template(body = "<%= hello %>", details = { format: :html })
  ActionView::Template.new(body, "hello template", details.fetch(:handler) { ERBHandler }, {:virtual_path => "hello"}.merge!(details))
end
render(locals = {})
# File actionview/test/template/template_test.rb, line 58
def render(locals = {})
  @template.render(@context, locals)
end
setup()
# File actionview/test/template/template_test.rb, line 62
def setup
  @context = Context.new
end
test_basic_template()
# File actionview/test/template/template_test.rb, line 66
def test_basic_template
  @template = new_template
  assert_equal "Hello", render
end
test_basic_template_does_html_escape()
# File actionview/test/template/template_test.rb, line 71
def test_basic_template_does_html_escape
  @template = new_template("<%= apostrophe %>")
  assert_equal "l&#39;apostrophe", render
end
test_default_external_works()

This test ensures that if the default_external is set to something other than UTF-8, we don't get any errors and get back a UTF-8 String.

# File actionview/test/template/template_test.rb, line 152
def test_default_external_works
  with_external_encoding "ISO-8859-1" do
    @template = new_template("hello \xFCmlat")
    assert_equal Encoding::UTF_8, render.encoding
    assert_equal "hello \u{fc}mlat", render
  end
end
test_encoding_can_be_specified_with_magic_comment()
# File actionview/test/template/template_test.rb, line 160
def test_encoding_can_be_specified_with_magic_comment
  @template = new_template("# encoding: ISO-8859-1\nhello \xFCmlat")
  assert_equal Encoding::UTF_8, render.encoding
  assert_equal "\nhello \u{fc}mlat", render
end
test_encoding_can_be_specified_with_magic_comment_in_erb()
# File actionview/test/template/template_test.rb, line 176
def test_encoding_can_be_specified_with_magic_comment_in_erb
  with_external_encoding Encoding::UTF_8 do
    @template = new_template("<%# encoding: ISO-8859-1 %>hello \xFCmlat", :virtual_path => nil)
    assert_equal Encoding::UTF_8, render.encoding
    assert_equal "hello \u{fc}mlat", render
  end
end
test_error_when_template_isnt_valid_utf8()
# File actionview/test/template/template_test.rb, line 184
def test_error_when_template_isnt_valid_utf8
  assert_raises(ActionView::Template::Error, /\xFC/) do
    @template = new_template("hello \xFCmlat", :virtual_path => nil)
    render
  end
end
test_locals()
# File actionview/test/template/template_test.rb, line 98
def test_locals
  @template = new_template("<%= my_local %>")
  @template.locals = [:my_local]
  assert_equal "I am a local", render(:my_local => "I am a local")
end
test_lying_with_magic_comment()

TODO: This is currently handled inside ERB. The case of explicitly lying about encodings via the normal Rails API should be handled inside Rails.

# File actionview/test/template/template_test.rb, line 169
def test_lying_with_magic_comment
  assert_raises(ActionView::Template::Error) do
    @template = new_template("# encoding: UTF-8\nhello \xFCmlat", :virtual_path => nil)
    render
  end
end
test_no_magic_comment_word_with_utf_8()
# File actionview/test/template/template_test.rb, line 143
def test_no_magic_comment_word_with_utf_8
  @template = new_template("hello \u{fc}mlat")
  assert_equal Encoding::UTF_8, render.encoding
  assert_equal "hello \u{fc}mlat", render
end
test_raw_template()
# File actionview/test/template/template_test.rb, line 81
def test_raw_template
  @template = new_template("<%= hello %>", :handler => ActionView::Template::Handlers::Raw.new)
  assert_equal "<%= hello %>", render
end
test_refresh_raises_an_error_without_virtual_path()
# File actionview/test/template/template_test.rb, line 131
def test_refresh_raises_an_error_without_virtual_path
  @template = new_template("Hello", :virtual_path => nil)
  assert_raise RuntimeError do
    @template.refresh(@context)
  end
end
test_refresh_with_partials()
# File actionview/test/template/template_test.rb, line 124
def test_refresh_with_partials
  @template = new_template("Hello", :virtual_path => "test/_foo")
  @template.locals = [:key]
  @context.lookup_context.expects(:find_template).with("foo", %w(test), true, [:key]).returns("partial")
  assert_equal "partial", @template.refresh(@context)
end
test_refresh_with_templates()
# File actionview/test/template/template_test.rb, line 117
def test_refresh_with_templates
  @template = new_template("Hello", :virtual_path => "test/foo/bar")
  @template.locals = [:key]
  @context.lookup_context.expects(:find_template).with("bar", %w(test/foo), false, [:key]).returns("template")
  assert_equal "template", @template.refresh(@context)
end
test_restores_buffer()
# File actionview/test/template/template_test.rb, line 104
def test_restores_buffer
  @template = new_template
  assert_equal "Hello", render
  assert_equal "original", @context.my_buffer
end
test_resulting_string_is_utf8()
# File actionview/test/template/template_test.rb, line 138
def test_resulting_string_is_utf8
  @template = new_template
  assert_equal Encoding::UTF_8, render.encoding
end
test_template_does_not_lose_its_source_after_rendering_if_it_does_not_have_a_virtual_path()
# File actionview/test/template/template_test.rb, line 92
def test_template_does_not_lose_its_source_after_rendering_if_it_does_not_have_a_virtual_path
  @template = new_template("Hello", :virtual_path => nil)
  render
  assert_equal "Hello", @template.source
end
test_template_loses_its_source_after_rendering()
# File actionview/test/template/template_test.rb, line 86
def test_template_loses_its_source_after_rendering
  @template = new_template
  render
  assert_nil @template.source
end
test_text_template_does_not_html_escape()
# File actionview/test/template/template_test.rb, line 76
def test_text_template_does_not_html_escape
  @template = new_template("<%= apostrophe %> <%== apostrophe %>", format: :text)
  assert_equal "l'apostrophe l'apostrophe", render
end
test_virtual_path()
# File actionview/test/template/template_test.rb, line 110
def test_virtual_path
  @template = new_template("<%= @virtual_path %>"                               "<%= partial.render(self, {}) %>"                               "<%= @virtual_path %>")
  assert_equal "hellopartialhello", render
end
with_external_encoding(encoding)
# File actionview/test/template/template_test.rb, line 191
def with_external_encoding(encoding)
  old = Encoding.default_external
  Encoding::Converter.new old, encoding if old != encoding
  silence_warnings { Encoding.default_external = encoding }
  yield
ensure
  silence_warnings { Encoding.default_external = old }
end