mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
inspect
for AR model classes does not initiate a new connection.
This commit is contained in:
parent
bfc8ffa232
commit
0f3aadae3b
3 changed files with 33 additions and 0 deletions
|
@ -1,3 +1,14 @@
|
|||
* `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 @@ module ActiveRecord
|
|||
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})"
|
||||
|
|
20
activerecord/test/cases/invalid_connection_test.rb
Normal file
20
activerecord/test/cases/invalid_connection_test.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
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
|
Loading…
Reference in a new issue