aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Azuma <dazuma@gmail.com>2013-01-29 17:59:08 -0800
committerDaniel Azuma <dazuma@gmail.com>2013-01-30 10:52:47 -0800
commita257d4818a0f95b0b2521146d53b5f5bce3f5c60 (patch)
treeec63253660a16d46601132f576fdf9d63f96509e
parentefd2be35510af7b02e70e4c5939720d7b12bc1c1 (diff)
downloadrails-a257d4818a0f95b0b2521146d53b5f5bce3f5c60.tar.gz
rails-a257d4818a0f95b0b2521146d53b5f5bce3f5c60.tar.bz2
rails-a257d4818a0f95b0b2521146d53b5f5bce3f5c60.zip
Raise a specific exception with a useful message if a rake task is requested for an unknown adapter
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb4
-rw-r--r--activerecord/test/cases/tasks/database_tasks_test.rb6
2 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index 67c7e714e6..4fa7cf8a7d 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -1,6 +1,7 @@
module ActiveRecord
module Tasks # :nodoc:
class DatabaseAlreadyExists < StandardError; end # :nodoc:
+ class DatabaseNotSupported < StandardError; end # :nodoc:
module DatabaseTasks # :nodoc:
extend self
@@ -121,6 +122,9 @@ module ActiveRecord
def class_for_adapter(adapter)
key = @tasks.keys.detect { |pattern| adapter[pattern] }
+ unless key
+ raise DatabaseNotSupported, "Rake tasks not supported by '#{adapter}' adapter"
+ end
@tasks[key]
end
diff --git a/activerecord/test/cases/tasks/database_tasks_test.rb b/activerecord/test/cases/tasks/database_tasks_test.rb
index 659d5eae72..3bfbc92afd 100644
--- a/activerecord/test/cases/tasks/database_tasks_test.rb
+++ b/activerecord/test/cases/tasks/database_tasks_test.rb
@@ -31,6 +31,12 @@ module ActiveRecord
ActiveRecord::Tasks::DatabaseTasks.register_task(/foo/, klazz)
ActiveRecord::Tasks::DatabaseTasks.structure_dump({'adapter' => :foo}, "awesome-file.sql")
end
+
+ def test_unregistered_task
+ assert_raise(ActiveRecord::Tasks::DatabaseNotSupported) do
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump({'adapter' => :bar}, "awesome-file.sql")
+ end
+ end
end
class DatabaseTasksCreateTest < ActiveRecord::TestCase