提交 a7ed92bd 编写于 作者: P Petrik

Use superclass name in inspect of ActionView::Base.with_empty_template_cache

When rendering views an anonymous subclass is created by calling
ActionView::Base.with_empty_template_cache.
This causes inspect to return an unhelpful description when calling
inspect:
`#<#<Class:0x012345012345>:<0x012345012345>`.

This can be confusing when exceptions are raised because it's hard to
figure out where to look. For example calling an undefined method in a
template would raise the following exception:

    undefined method `undefined' for #<#<Class:0x012345012345>:<0x012345012345>

Instead we can return the non-anonymous superclass name.

    undefined method `undefined' for #<ActionView::Base:0x01234502345>

The anonymous class is created in ActionView::Base.with_empty_template_cache.
See f9bea630
This seems to be done for performance reasons only, without expecting a
change to calling `inspect`.
上级 8a578c46
......@@ -190,6 +190,14 @@ def with_empty_template_cache # :nodoc:
# correctly.
define_method(:compiled_method_container) { subclass }
define_singleton_method(:compiled_method_container) { subclass }
def self.name
superclass.name
end
def inspect
"#<#{self.class.name}:#{'%#016x' % (object_id << 1)}>"
end
}
end
......
......@@ -327,6 +327,11 @@ def test_render_file_with_errors
assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
end
def test_undefined_method_error_references_named_class
e = assert_raises(ActionView::Template::Error) { @view.render(inline: "<%= undefined %>") }
assert_match(/`undefined' for #<ActionView::Base:0x[0-9a-f]+>/, e.message)
end
def test_render_object
assert_equal "Hello: david", @view.render(partial: "test/customer", object: Customer.new("david"))
assert_equal "FalseClass", @view.render(partial: "test/klass", object: false)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册