aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-03-06 23:30:11 +0900
committerRyuta Kamizono <kamipo@gmail.com>2019-03-06 23:45:08 +0900
commitfd18b98dd90d738af265cf5b8f0d66ca11010132 (patch)
treeadaa5ffd1a5d3ef8fda9ec2945db1888ff7cfba5 /activerecord/test/cases/migration
parentb366be3b5b28f01c8a55d67a5161ec36f53d555c (diff)
downloadrails-fd18b98dd90d738af265cf5b8f0d66ca11010132.tar.gz
rails-fd18b98dd90d738af265cf5b8f0d66ca11010132.tar.bz2
rails-fd18b98dd90d738af265cf5b8f0d66ca11010132.zip
Allow `remove_foreign_key` with both `to_table` and `options`
Foreign keys could be created to the same table. So `remove_foreign_key :from_table, :to_table` is sometimes ambiguous. This allows `remove_foreign_key` to remove the select one on the same table with giving both `to_table` and `options`.
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r--activerecord/test/cases/migration/foreign_key_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/foreign_key_test.rb b/activerecord/test/cases/migration/foreign_key_test.rb
index 6547ebb5d1..da82f62406 100644
--- a/activerecord/test/cases/migration/foreign_key_test.rb
+++ b/activerecord/test/cases/migration/foreign_key_test.rb
@@ -385,6 +385,18 @@ if ActiveRecord::Base.connection.supports_foreign_keys?
assert_equal "Table 'astronauts' has no foreign key for rockets", e.message
end
+ def test_remove_foreign_key_by_the_select_one_on_the_same_table
+ @connection.add_foreign_key :astronauts, :rockets
+ @connection.add_reference :astronauts, :myrocket, foreign_key: { to_table: :rockets }
+
+ assert_equal 2, @connection.foreign_keys("astronauts").size
+
+ @connection.remove_foreign_key :astronauts, :rockets, column: "myrocket_id"
+
+ assert_equal [["astronauts", "rockets", "rocket_id"]],
+ @connection.foreign_keys("astronauts").map { |fk| [fk.from_table, fk.to_table, fk.column] }
+ end
+
if ActiveRecord::Base.connection.supports_validate_constraints?
def test_add_invalid_foreign_key
@connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", validate: false