diff options
author | schneems <richard.schneeman@gmail.com> | 2013-11-11 15:56:09 -0500 |
---|---|---|
committer | schneems <richard.schneeman@gmail.com> | 2013-12-23 10:23:48 -0500 |
commit | 0ec45cd15d0a2f5aebc75e23d841b6c12f3ba763 (patch) | |
tree | e1993de87e010ba4c917c605d8b85fc0fe6bad5a /activerecord/test | |
parent | b4d7be95e635da64b99e833a93c345bb4d6f2ba2 (diff) | |
download | rails-0ec45cd15d0a2f5aebc75e23d841b6c12f3ba763.tar.gz rails-0ec45cd15d0a2f5aebc75e23d841b6c12f3ba763.tar.bz2 rails-0ec45cd15d0a2f5aebc75e23d841b6c12f3ba763.zip |
Tell how to Create a Database in Error Message
Currently if you attempt to use a database that does not exist you get an error:
```
PG::ConnectionBad FATAL: database "db_error" does not exist
```
The solution is easy, create and migrate your database however new developers may not know these commands by memory. Instead of requiring the developer to search for a solution, tell them how to fix the problem in the error message:
```
ActiveRecord::NoDatabase: FATAL: database "db_error" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
```
Active Record should not know about `rake db:migrate` so this additional information needs to come from the railtie. Potential alternative implementation suggestions are welcome.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index 5372f8821f..778175e2e8 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -10,6 +10,13 @@ module ActiveRecord @connection.exec_query('create table ex(id serial primary key, number integer, data character varying(255))') end + def test_bad_connection + assert_raise ActiveRecord::NoDatabaseError do + connection = ActiveRecord::Base.postgresql_connection(database: "should_not_exist-cinco-dog-db", adapter: "postgresql") + connection.exec_query('drop table if exists ex') + end + end + def test_valid_column column = @connection.columns('ex').find { |col| col.name == 'id' } assert @connection.valid_type?(column.type) |