提交 362348b5 编写于 作者: R Ryuta Kamizono

`add_foreign_key`'s arguments are compatible (invertable) for...

`add_foreign_key`'s arguments are compatible (invertable) for `remove_foreign_key` without customize

So the custom `invert_add_foreign_key` is a little redundant.
上级 7d654787
......@@ -127,6 +127,7 @@ module StraightReversions # :nodoc:
add_column: :remove_column,
add_timestamps: :remove_timestamps,
add_reference: :remove_reference,
add_foreign_key: :remove_foreign_key,
enable_extension: :disable_extension
}.each do |cmd, inv|
[[inv, cmd], [cmd, inv]].uniq.each do |method, inverse|
......@@ -217,21 +218,6 @@ def invert_change_column_null(args)
[:change_column_null, args]
end
def invert_add_foreign_key(args)
from_table, to_table, add_options = args
add_options ||= {}
if add_options[:name]
options = { name: add_options[:name] }
elsif add_options[:column]
options = { column: add_options[:column] }
else
options = to_table
end
[:remove_foreign_key, [from_table, options]]
end
def invert_remove_foreign_key(args)
options = args.extract_options!
from_table, to_table = args
......
......@@ -337,7 +337,7 @@ def test_invert_disable_extension
def test_invert_add_foreign_key
enable = @recorder.inverse_of :add_foreign_key, [:dogs, :people]
assert_equal [:remove_foreign_key, [:dogs, :people]], enable
assert_equal [:remove_foreign_key, [:dogs, :people], nil], enable
end
def test_invert_remove_foreign_key
......@@ -347,7 +347,7 @@ def test_invert_remove_foreign_key
def test_invert_add_foreign_key_with_column
enable = @recorder.inverse_of :add_foreign_key, [:dogs, :people, column: "owner_id"]
assert_equal [:remove_foreign_key, [:dogs, column: "owner_id"]], enable
assert_equal [:remove_foreign_key, [:dogs, :people, column: "owner_id"], nil], enable
end
def test_invert_remove_foreign_key_with_column
......@@ -357,7 +357,7 @@ def test_invert_remove_foreign_key_with_column
def test_invert_add_foreign_key_with_column_and_name
enable = @recorder.inverse_of :add_foreign_key, [:dogs, :people, column: "owner_id", name: "fk"]
assert_equal [:remove_foreign_key, [:dogs, name: "fk"]], enable
assert_equal [:remove_foreign_key, [:dogs, :people, column: "owner_id", name: "fk"], nil], enable
end
def test_invert_remove_foreign_key_with_column_and_name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册