diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-02-16 09:08:38 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-02-16 09:39:59 +0100 |
commit | 6bd777c85156aca0cf2d1f34d8c1fe37d96ac3d9 (patch) | |
tree | e12a4abb9b323d80de9d5af7556dad301d3a18d8 /activerecord/test | |
parent | 8980da84bc33b0e2b36c92362d74280658441581 (diff) | |
parent | f0ae503d1931a2f269db3437550be3173ba06bce (diff) | |
download | rails-6bd777c85156aca0cf2d1f34d8c1fe37d96ac3d9.tar.gz rails-6bd777c85156aca0cf2d1f34d8c1fe37d96ac3d9.tar.bz2 rails-6bd777c85156aca0cf2d1f34d8c1fe37d96ac3d9.zip |
Merge pull request #18662 from estum/foreign-key-exists
Add `foreign_key_exists?` method.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/migration/foreign_key_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/foreign_key_test.rb b/activerecord/test/cases/migration/foreign_key_test.rb index b2f2d077eb..7f4790bf3e 100644 --- a/activerecord/test/cases/migration/foreign_key_test.rb +++ b/activerecord/test/cases/migration/foreign_key_test.rb @@ -147,6 +147,27 @@ module ActiveRecord assert_equal :nullify, fk.on_update end + def test_foreign_key_exists + @connection.add_foreign_key :astronauts, :rockets + + assert @connection.foreign_key_exists?(:astronauts, :rockets) + assert_not @connection.foreign_key_exists?(:astronauts, :stars) + end + + def test_foreign_key_exists_by_column + @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id" + + assert @connection.foreign_key_exists?(:astronauts, column: "rocket_id") + assert_not @connection.foreign_key_exists?(:astronauts, column: "star_id") + end + + def test_foreign_key_exists_by_name + @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", name: "fancy_named_fk" + + assert @connection.foreign_key_exists?(:astronauts, name: "fancy_named_fk") + assert_not @connection.foreign_key_exists?(:astronauts, name: "other_fancy_named_fk") + end + def test_remove_foreign_key_inferes_column @connection.add_foreign_key :astronauts, :rockets |