提交 5ac22989 编写于 作者: P Piotr Sarnacki

Merge pull request #11014 from senny/10936_inspect_does_not_crash_without_connection

`inspect` for AR model classes does not initiate a new connection.
* `inspect` on Active Record model classes does not initiate a
new connection. This means that calling `inspect`, when the
database is missing, will no longer raise an exception.
Fixes #10936.
Example:
Author.inspect # => "Author(no database connection)"
*Yves Senn*
* Handle single quotes in PostgreSQL default column values.
Fixes #10881.
......
......@@ -123,6 +123,8 @@ def inspect
super
elsif abstract_class?
"#{super}(abstract)"
elsif !connected?
"#{super}(no database connection)"
elsif table_exists?
attr_list = columns.map { |c| "#{c.name}: #{c.type}" } * ', '
"#{super}(#{attr_list})"
......
require "cases/helper"
require "models/bird"
class TestAdapterWithInvalidConnection < ActiveRecord::TestCase
self.use_transactional_fixtures = false
def setup
@spec = ActiveRecord::Base.connection_config
non_existing_spec = {adapter: @spec[:adapter], database: "i_do_not_exist"}
ActiveRecord::Base.establish_connection(non_existing_spec)
end
def teardown
ActiveRecord::Base.establish_connection(@spec)
end
test "inspect on Model class does not raise" do
assert_equal "Bird(no database connection)", Bird.inspect
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册