diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-06-19 18:27:13 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-06-20 07:21:04 +0200 |
commit | 0f3aadae3b639ce56dba9c1bcf8a3c3646ccc93b (patch) | |
tree | 3f343c8d5648bccda1294f618f06a649e0767a3a /activerecord | |
parent | bfc8ffa2327ac6e3949507e71dba04dd3a6c9131 (diff) | |
download | rails-0f3aadae3b639ce56dba9c1bcf8a3c3646ccc93b.tar.gz rails-0f3aadae3b639ce56dba9c1bcf8a3c3646ccc93b.tar.bz2 rails-0f3aadae3b639ce56dba9c1bcf8a3c3646ccc93b.zip |
`inspect` for AR model classes does not initiate a new connection.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 11 | ||||
-rw-r--r-- | activerecord/lib/active_record/core.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/invalid_connection_test.rb | 20 |
3 files changed, 33 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 128d1b3e7f..b24222b700 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -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. diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index ba053700f2..f0141aaaab 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -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})" diff --git a/activerecord/test/cases/invalid_connection_test.rb b/activerecord/test/cases/invalid_connection_test.rb new file mode 100644 index 0000000000..f6fe7f0d7d --- /dev/null +++ b/activerecord/test/cases/invalid_connection_test.rb @@ -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 |