Permalink
Browse files

Merge pull request #9119 from dazuma/database_tasks_for_unknown_adapter

Raise an exception with a useful message if a rake task is requested for an unknown adapter
  • Loading branch information...
2 parents 9ec14c2 + a257d48 commit 18e889f91baf3146055b1a0e7c661310ba232ab4 @carlosantoniodasilva carlosantoniodasilva committed Jan 31, 2013
@@ -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
@@ -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 18e889f

Please sign in to comment.