diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-06 17:24:46 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-26 22:03:48 +0200 |
commit | e2ef25710682d884b2e6f5e99d47f18eb7083c68 (patch) | |
tree | 2024740056e51305e2d5bdf049407f4aca7ae731 /activerecord/test | |
parent | 5add8b8d6d27afac9fe46bcee09cd341fb124294 (diff) | |
download | rails-e2ef25710682d884b2e6f5e99d47f18eb7083c68.tar.gz rails-e2ef25710682d884b2e6f5e99d47f18eb7083c68.tar.bz2 rails-e2ef25710682d884b2e6f5e99d47f18eb7083c68.zip |
fk: `add_foreign_key` and `remove_foreign_key` for PostgreSQL adapter.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/migration/foreign_key_test.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/foreign_key_test.rb b/activerecord/test/cases/migration/foreign_key_test.rb new file mode 100644 index 0000000000..978d1a8cf1 --- /dev/null +++ b/activerecord/test/cases/migration/foreign_key_test.rb @@ -0,0 +1,49 @@ +require 'cases/helper' + +if ActiveRecord::Base.connection.supports_foreign_keys? +module ActiveRecord + class Migration + class ForeignKeyTest < ActiveRecord::TestCase + class Rocket < ActiveRecord::Base + end + + class Astronaut < ActiveRecord::Base + end + + setup do + @connection = ActiveRecord::Base.connection + @connection.create_table "rockets" do |t| + t.string :name + end + + @connection.create_table "astronauts" do |t| + t.string :name + t.references :rocket + end + 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 + 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 + 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 + end + end + end +end +end |