diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-08-19 09:09:38 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-08-19 09:09:38 +0900 |
commit | dc796a0d407dfaf84abd464fc1aa2966cddb51e0 (patch) | |
tree | 04126ceaabd5afe04c354f81f54801fbdf9277ec /activerecord | |
parent | b2c1e29c14b91b290b30c928c63253d1555e0fd9 (diff) | |
download | rails-dc796a0d407dfaf84abd464fc1aa2966cddb51e0.tar.gz rails-dc796a0d407dfaf84abd464fc1aa2966cddb51e0.tar.bz2 rails-dc796a0d407dfaf84abd464fc1aa2966cddb51e0.zip |
Ensure `foreign_keys` assertions after alter table
If `foreign_keys` is fetched before alter table, it couldn't notice
whether foreign keys are broken or not after alter table.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/test/cases/migration/foreign_key_test.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/test/cases/migration/foreign_key_test.rb b/activerecord/test/cases/migration/foreign_key_test.rb index 7b755787c7..4b4cdf141e 100644 --- a/activerecord/test/cases/migration/foreign_key_test.rb +++ b/activerecord/test/cases/migration/foreign_key_test.rb @@ -53,12 +53,14 @@ if ActiveRecord::Base.connection.supports_foreign_keys_in_create? end def test_change_column_of_parent_table - foreign_keys = ActiveRecord::Base.connection.foreign_keys("astronauts") rocket = Rocket.create!(name: "myrocket") rocket.astronauts << Astronaut.create! @connection.change_column_null :rockets, :name, false + foreign_keys = @connection.foreign_keys("astronauts") + assert_equal 1, foreign_keys.size + fk = foreign_keys.first assert_equal "myrocket", Rocket.first.name assert_equal "astronauts", fk.from_table @@ -72,6 +74,8 @@ if ActiveRecord::Base.connection.supports_foreign_keys_in_create? @connection.rename_column :astronauts, :name, :astronaut_name foreign_keys = @connection.foreign_keys("astronauts") + assert_equal 1, foreign_keys.size + fk = foreign_keys.first assert_equal "myrocket", Rocket.first.name assert_equal "astronauts", fk.from_table |