aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorIvan Antropov <antropov.ivan@gmail.com>2013-10-26 12:35:59 +0700
committerIvan Antropov <antropov.ivan@gmail.com>2013-10-26 12:35:59 +0700
commit87d1aba3cba0d9b02490784b3090b0e5c94f56df (patch)
tree032f9bc83d33ed12964716a1bdc53d53e4253cb3 /activerecord/test
parentfa915461bc4892b8d53d3d4e202ba16f0dbdfe12 (diff)
downloadrails-87d1aba3cba0d9b02490784b3090b0e5c94f56df.tar.gz
rails-87d1aba3cba0d9b02490784b3090b0e5c94f56df.tar.bz2
rails-87d1aba3cba0d9b02490784b3090b0e5c94f56df.zip
Fix bug, when ':dependent => :destroy' option violates foreign key constraints, issue #12380
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index a79f145e31..19a8ae75ea 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -831,3 +831,39 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal post.author_id, author2.id
end
end
+
+class BelongsToWithForeignKeyTest < ActiveRecord::TestCase
+ def setup
+ ActiveRecord::Schema.define do
+ drop_table :authors, if_exists: true
+ drop_table :author_addresses, if_exists: true
+
+ create_table :author_addresses do |t|
+ end
+
+ exec_query <<-eos
+ create table authors(
+ id int,
+ author_address_id int,
+ name varchar(255),
+ PRIMARY KEY (id),
+ FOREIGN KEY (author_address_id) REFERENCES author_addresses(id)
+ );
+ eos
+ end
+ end
+
+ def teardown
+ ActiveRecord::Schema.define do
+ drop_table :authors, if_exists: true
+ drop_table :author_addresses, if_exists: true
+ end
+ end
+
+ def test_destroy_linked_models
+ address = AuthorAddress.create!
+ author = Author.create! id: 1, name: "Author", author_address_id: address.id
+
+ author.destroy!
+ end
+end