diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-10 10:59:18 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-26 22:03:48 +0200 |
commit | 09b3a2847ca51d0e5dcebcb636d8770b19c397a7 (patch) | |
tree | 00d830e0b75f72253861907e5514b84b6a9c3e13 /activerecord/test | |
parent | e2ef25710682d884b2e6f5e99d47f18eb7083c68 (diff) | |
download | rails-09b3a2847ca51d0e5dcebcb636d8770b19c397a7.tar.gz rails-09b3a2847ca51d0e5dcebcb636d8770b19c397a7.tar.bz2 rails-09b3a2847ca51d0e5dcebcb636d8770b19c397a7.zip |
fk: add `foreign_keys` for PostgreSQL adapter.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/migration/foreign_key_test.rb | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/activerecord/test/cases/migration/foreign_key_test.rb b/activerecord/test/cases/migration/foreign_key_test.rb index 978d1a8cf1..9c804c12d1 100644 --- a/activerecord/test/cases/migration/foreign_key_test.rb +++ b/activerecord/test/cases/migration/foreign_key_test.rb @@ -22,26 +22,46 @@ module ActiveRecord end end + def test_foreign_keys + foreign_keys = @connection.foreign_keys("fk_test_has_fk") + assert_equal 1, foreign_keys.size + + fk = foreign_keys.first + assert_equal "fk_test_has_fk", fk.from_table + assert_equal "fk_test_has_pk", fk.to_table + assert_equal "fk_id", fk.column + assert_equal "id", fk.primary_key + assert_equal "fk_name", fk.name + end + def test_add_foreign_key @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id" - assert_raises ActiveRecord::InvalidForeignKey do - Astronaut.create rocket_id: 33 - end + foreign_keys = @connection.foreign_keys("astronauts") + assert_equal 1, foreign_keys.size + + fk = foreign_keys.first + assert_equal "astronauts", fk.from_table + assert_equal "rockets", fk.to_table + assert_equal "rocket_id", fk.column + assert_equal "id", fk.primary_key + assert_equal "astronauts_rocket_id_fk", fk.name end def test_remove_foreign_key @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id" - @connection.remove_foreign_key :astronauts, column: "rocket_id" - Astronaut.create rocket_id: 33 + assert_equal 1, @connection.foreign_keys("astronauts").size + @connection.remove_foreign_key :astronauts, column: "rocket_id" + assert_equal [], @connection.foreign_keys("astronauts") end def test_remove_foreign_key_by_name @connection.add_foreign_key :astronauts, :rockets, column: "rocket_id", name: "fancy_named_fk" - @connection.remove_foreign_key :astronauts, name: "fancy_named_fk" - Astronaut.create rocket_id: 33 + assert_equal 1, @connection.foreign_keys("astronauts").size + @connection.remove_foreign_key :astronauts, name: "fancy_named_fk" + assert_equal [], @connection.foreign_keys("astronauts") end end end |