aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/invertible_migration_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-05-31 12:52:42 -0400
committerSean Griffin <sean@seantheprogrammer.com>2016-05-31 12:55:02 -0400
commit56a61e0c439d75244992f01468f09f85b5b08b78 (patch)
tree113aec28c51f6de43d002d33171070c5470c4306 /activerecord/test/cases/invertible_migration_test.rb
parent0419e1b6f395e94d81e0709642486433baafd967 (diff)
downloadrails-56a61e0c439d75244992f01468f09f85b5b08b78.tar.gz
rails-56a61e0c439d75244992f01468f09f85b5b08b78.tar.bz2
rails-56a61e0c439d75244992f01468f09f85b5b08b78.zip
Respect options passed to `foreign_key` when reverting `add_reference`
The code incorrectly assumes that the option was written as `foreign_key: true`, but that is not always the case. This now mirrors the behavior of reverting `add_foreign_key`. The code was changed to use kwargs while I was touching it, as well. This could really use a refactoring to go through the same code paths as `add_refernce` in the future, so we don't duplicate default values. Fixes #25169
Diffstat (limited to 'activerecord/test/cases/invertible_migration_test.rb')
-rw-r--r--activerecord/test/cases/invertible_migration_test.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/invertible_migration_test.rb b/activerecord/test/cases/invertible_migration_test.rb
index e030f6c588..aba854820b 100644
--- a/activerecord/test/cases/invertible_migration_test.rb
+++ b/activerecord/test/cases/invertible_migration_test.rb
@@ -151,6 +151,14 @@ module ActiveRecord
end
end
+ class RevertCustomForeignKeyTable < SilentMigration
+ def change
+ change_table(:horses) do |t|
+ t.references :owner, foreign_key: { to_table: :developers }
+ end
+ end
+ end
+
setup do
@verbose_was, ActiveRecord::Migration.verbose = ActiveRecord::Migration.verbose, false
end
@@ -353,6 +361,13 @@ module ActiveRecord
ActiveRecord::Base.table_name_prefix = ActiveRecord::Base.table_name_suffix = ''
end
+ def test_migrations_can_handle_foreign_keys_to_specific_tables
+ migration = RevertCustomForeignKeyTable.new
+ InvertibleMigration.migrate(:up)
+ migration.migrate(:up)
+ migration.migrate(:down)
+ end
+
# MySQL 5.7 and Oracle do not allow to create duplicate indexes on the same columns
unless current_adapter?(:Mysql2Adapter, :OracleAdapter)
def test_migrate_revert_add_index_with_name