mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #41760 from Shopify/register-task-precedence
Give precedence to the DatabaseTasks registered last
This commit is contained in:
commit
30ef29289b
2 changed files with 16 additions and 1 deletions
|
@ -537,7 +537,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def class_for_adapter(adapter)
|
||||
_key, task = @tasks.each_pair.detect { |pattern, _task| adapter[pattern] }
|
||||
_key, task = @tasks.reverse_each.detect { |pattern, _task| adapter[pattern] }
|
||||
unless task
|
||||
raise DatabaseNotSupported, "Rake tasks not supported by '#{adapter}' adapter"
|
||||
end
|
||||
|
|
|
@ -185,6 +185,21 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def test_register_task_precedence
|
||||
klazz = Class.new do
|
||||
def initialize(*arguments); end
|
||||
def structure_dump(filename); end
|
||||
end
|
||||
instance = klazz.new
|
||||
|
||||
klazz.stub(:new, instance) do
|
||||
assert_called_with(instance, :structure_dump, ["awesome-file.sql", nil]) do
|
||||
ActiveRecord::Tasks::DatabaseTasks.register_task(/custom_mysql/, klazz)
|
||||
ActiveRecord::Tasks::DatabaseTasks.structure_dump({ "adapter" => :custom_mysql }, "awesome-file.sql")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_unregistered_task
|
||||
assert_raise(ActiveRecord::Tasks::DatabaseNotSupported) do
|
||||
ActiveRecord::Tasks::DatabaseTasks.structure_dump({ "adapter" => :bar }, "awesome-file.sql")
|
||||
|
|
Loading…
Reference in a new issue