aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/tasks
diff options
context:
space:
mode:
authorJay Hayes <ur@iamvery.com>2013-10-14 11:20:51 -0500
committerJay Hayes <ur@iamvery.com>2013-11-11 07:54:30 -0600
commit22f80ae57b26907f662b7fd50a7270a6381e527e (patch)
treefed6f18701451f9a7a7237cd1061f4f5e5181b43 /activerecord/test/cases/tasks
parenta11ddbe55fd27f38e0085ee1210947e3d8f47220 (diff)
downloadrails-22f80ae57b26907f662b7fd50a7270a6381e527e.tar.gz
rails-22f80ae57b26907f662b7fd50a7270a6381e527e.tar.bz2
rails-22f80ae57b26907f662b7fd50a7270a6381e527e.zip
Explicitly exit with status "1" for create and drop failures
* A non-zero exit status allows subsequent shell commands to be chained together such as: `rake db:reset test:prepare && rspec && cap deploy` (if you're feeling brave :) * Any exceptions raised during the `create` and `drop` tasks are caught in order to print a "pretty" message to the user. Unfortunately doing so prevents rake from aborting with a non-zero exit status to the shell. * Therefore we re-raise the exceptions after the "pretty" message and re-catch them in the task. * From the task we explicitly exit with a non-zero status. This method was chosen (rather than just letting rake fail from the exception) so that the backtrace is suppressed and the output to stderr is unchanged. * Update activerecord CHANGELOG
Diffstat (limited to 'activerecord/test/cases/tasks')
-rw-r--r--activerecord/test/cases/tasks/mysql_rake_test.rb4
-rw-r--r--activerecord/test/cases/tasks/postgresql_rake_test.rb8
-rw-r--r--activerecord/test/cases/tasks/sqlite_rake_test.rb12
3 files changed, 18 insertions, 6 deletions
diff --git a/activerecord/test/cases/tasks/mysql_rake_test.rb b/activerecord/test/cases/tasks/mysql_rake_test.rb
index 816bd62751..df1dad1622 100644
--- a/activerecord/test/cases/tasks/mysql_rake_test.rb
+++ b/activerecord/test/cases/tasks/mysql_rake_test.rb
@@ -61,7 +61,9 @@ module ActiveRecord
ActiveRecord::StatementInvalid.new("Can't create database 'dev'; database exists:")
)
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ assert_raises(ActiveRecord::Tasks::DatabaseAlreadyExists) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ end
end
end
diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb
index f31896bc7f..3e02763ed0 100644
--- a/activerecord/test/cases/tasks/postgresql_rake_test.rb
+++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb
@@ -59,7 +59,9 @@ module ActiveRecord
$stderr.expects(:puts).
with("Couldn't create database for #{@configuration.inspect}")
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ assert_raises(Exception) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ end
end
def test_create_when_database_exists_outputs_info_to_stderr
@@ -69,7 +71,9 @@ module ActiveRecord
ActiveRecord::StatementInvalid.new('database "my-app-db" already exists')
)
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ assert_raises(ActiveRecord::Tasks::DatabaseAlreadyExists) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
+ end
end
end
diff --git a/activerecord/test/cases/tasks/sqlite_rake_test.rb b/activerecord/test/cases/tasks/sqlite_rake_test.rb
index 7209c0f14d..e5f66c092b 100644
--- a/activerecord/test/cases/tasks/sqlite_rake_test.rb
+++ b/activerecord/test/cases/tasks/sqlite_rake_test.rb
@@ -27,7 +27,9 @@ module ActiveRecord
$stderr.expects(:puts).with("#{@database} already exists")
- ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root'
+ assert_raises(ActiveRecord::Tasks::DatabaseAlreadyExists) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root'
+ end
end
def test_db_create_with_file_does_nothing
@@ -36,7 +38,9 @@ module ActiveRecord
ActiveRecord::Base.expects(:establish_connection).never
- ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root'
+ assert_raises(ActiveRecord::Tasks::DatabaseAlreadyExists) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root'
+ end
end
def test_db_create_establishes_a_connection
@@ -52,7 +56,9 @@ module ActiveRecord
$stderr.expects(:puts).
with("Couldn't create database for #{@configuration.inspect}")
- ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root'
+ assert_raises(Exception) do
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root'
+ end
end
end