Browse files

Raise a specific exception with a useful message if a rake task is re…

…quested for an unknown adapter
  • Loading branch information...
1 parent efd2be3 commit a257d4818a0f95b0b2521146d53b5f5bce3f5c60 @dazuma dazuma committed Jan 29, 2013
View
4 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 @@ def database_url_config
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
View
6 activerecord/test/cases/tasks/database_tasks_test.rb
@@ -31,6 +31,12 @@ def structure_dump(filename); end
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

0 comments on commit a257d48

Please sign in to comment.