aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-12-18 10:07:23 +0100
committerYves Senn <yves.senn@gmail.com>2014-12-19 11:27:04 +0100
commitbe1e0241f012f1151d2448b10e14b8b2eda26b84 (patch)
treee3060d4868ebc476830e9939e4c275d4a2a8a0fc /activerecord/test/cases/migration
parent36ce0c2c821e2c9cca15e768842461f834825bf7 (diff)
downloadrails-be1e0241f012f1151d2448b10e14b8b2eda26b84.tar.gz
rails-be1e0241f012f1151d2448b10e14b8b2eda26b84.tar.bz2
rails-be1e0241f012f1151d2448b10e14b8b2eda26b84.zip
`force: :cascade` to recreate tables referenced by foreign-keys.
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r--activerecord/test/cases/migration/change_schema_test.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration/change_schema_test.rb b/activerecord/test/cases/migration/change_schema_test.rb
index d91e7142b3..d774cfebc4 100644
--- a/activerecord/test/cases/migration/change_schema_test.rb
+++ b/activerecord/test/cases/migration/change_schema_test.rb
@@ -415,5 +415,36 @@ module ActiveRecord
yield
end
end
+
+ if ActiveRecord::Base.connection.supports_foreign_keys?
+ class ChangeSchemaWithDependentObjectsTest < ActiveRecord::TestCase
+ self.use_transactional_fixtures = false
+
+ setup do
+ @connection = ActiveRecord::Base.connection
+ @connection.create_table :trains
+ @connection.create_table(:wagons) { |t| t.references :train }
+ @connection.add_foreign_key :wagons, :trains
+ end
+
+ teardown do
+ [:wagons, :trains].each do |table|
+ @connection.drop_table(table) if @connection.table_exists?(table)
+ end
+ end
+
+ def test_create_table_with_force_cascade_drops_dependent_objects
+ skip "MySQL > 5.5 does not drop dependent objects with DROP TABLE CASCADE" if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
+ # can't re-create table referenced by foreign key
+ assert_raises(ActiveRecord::StatementInvalid) do
+ @connection.create_table :trains, force: true
+ end
+
+ # can recreate referenced table with force: :cascade
+ @connection.create_table :trains, force: :cascade
+ assert_equal [], @connection.foreign_keys(:wagons)
+ end
+ end
+ end
end
end