提交 080edb44 编写于 作者: P Petrik

Shorten inspect on AbstractController::Base

Calling self in an action of a controller generates an endless stream of
characters, including the request object and all instances variables.
This can be frustrating when using a debugger in a controller and
accidentally calling `self` generates output for a couple of seconds.

This shortens inspect to only show the class name.

    MyController.new.inspect # => "#<MyController:0x00000000005028>"
上级 3d27653d
......@@ -204,6 +204,10 @@ def self.supports_path?
true
end
def inspect # :nodoc:
"#<#{self.class.name}:#{'%#016x' % (object_id << 1)}>"
end
private
# Returns true if the name can be considered an action because
# it has a method defined in the controller.
......
......@@ -147,6 +147,10 @@ def test_response_has_default_headers
ensure
ActionDispatch::Response.default_headers = original_default_headers
end
def test_inspect
assert_match(/\A#<EmptyController:0x[0-9a-f]+>\z/, @empty.inspect)
end
end
class PerformActionTest < ActionController::TestCase
......
......@@ -29,4 +29,9 @@ def test_response_does_not_have_default_headers
ensure
ActionDispatch::Response.default_headers = original_default_headers
end
def test_inspect
controller = SimpleController.new
assert_match(/\A#<MetalControllerInstanceTests::SimpleController:0x[0-9a-f]+>\z/, controller.inspect)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册