Skip to content

Commit

Permalink
Raise a specific exception with a useful message if a rake task is re…
Browse files Browse the repository at this point in the history
…quested for an unknown adapter
  • Loading branch information
dazuma committed Jan 30, 2013
1 parent efd2be3 commit a257d48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/tasks/database_tasks_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit a257d48

Please sign in to comment.