diff options
author | Jay Hayes <ur@iamvery.com> | 2015-04-26 22:17:05 -0500 |
---|---|---|
committer | Jay Hayes <ur@iamvery.com> | 2015-10-20 19:17:58 -0500 |
commit | 213ff7ca0c27739715bda83a9c6237c03a577c2b (patch) | |
tree | 3c57fd5d09ba67827bdb87f4bc21a981d64d9221 /railties/test/application/rake | |
parent | 0d216d1add9eaaddfc0b02813ccf08fd22910859 (diff) | |
download | rails-213ff7ca0c27739715bda83a9c6237c03a577c2b.tar.gz rails-213ff7ca0c27739715bda83a9c6237c03a577c2b.tar.bz2 rails-213ff7ca0c27739715bda83a9c6237c03a577c2b.zip |
Add tests to verify exit status for create/drop failures
* Running the db:create task when the database already exists isn't
really an error case. That is processing may proceed in this case
because the database exists as requested. So let's validate that
behavior with a test.
* Likewise, if the database doesn't exist when running the db:drop task
processing may continue as the requested condition is already met.
Thus a test.
Diffstat (limited to 'railties/test/application/rake')
-rw-r--r-- | railties/test/application/rake/dbs_test.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index e7beab8b5e..8731b7d86b 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -49,6 +49,34 @@ module ApplicationTests db_create_and_drop database_url_db_name end + def with_database_existing + Dir.chdir(app_path) do + set_database_url + `bin/rake db:create` + yield + `bin/rake db:drop` + end + end + + test 'db:create failure because database exists' do + with_database_existing do + output = `bin/rake db:create 2>&1` + assert_match /already exists/, output + assert_equal 0, $?.exitstatus + end + end + + test 'db:drop failure because database does not exist' do + Dir.chdir(app_path) do + output = `bin/rake db:drop 2>&1` + # This assertion should work, but it does not. The SQLite3 adapter + # does not raise an error when nothing exists to drop. + # https://github.com/rails/rails/blob/f00554a8226b9529c38be1f3e61b6b1888682fb4/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L34-L37 + # assert_match /does not exist/, output + assert_equal 0, $?.exitstatus + end + end + def db_migrate_and_status(expected_database) Dir.chdir(app_path) do `bin/rails generate model book title:string; |