Created
May 14, 2011 02:18
-
-
Save AquaGeek/971655 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #3761
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 395886573c1b838a0951c642728f2a52bb9de77b Mon Sep 17 00:00:00 2001 | |
From: hemant <[email protected]> | |
Date: Sat, 26 Feb 2011 23:31:26 +0530 | |
Subject: [PATCH] tests to demonstrate inverse_of causes infinite loop with accepts_nested_attributes_for | |
--- | |
.../associations/inverse_associations_test.rb | 24 +++++++++++++++++++- | |
activerecord/test/models/bird.rb | 7 +++++- | |
activerecord/test/models/pirate.rb | 2 + | |
3 files changed, 31 insertions(+), 2 deletions(-) | |
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb | |
index 7628221..099ad1c 100644 | |
--- a/activerecord/test/cases/associations/inverse_associations_test.rb | |
+++ b/activerecord/test/cases/associations/inverse_associations_test.rb | |
@@ -5,6 +5,8 @@ require 'models/interest' | |
require 'models/zine' | |
require 'models/club' | |
require 'models/sponsor' | |
+require 'models/pirate' | |
+require 'models/bird' | |
class InverseAssociationTests < ActiveRecord::TestCase | |
def test_should_allow_for_inverse_of_options_in_associations | |
@@ -161,10 +163,21 @@ class InverseHasOneTests < ActiveRecord::TestCase | |
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error | |
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.find(:first).dirty_face } | |
end | |
+ | |
+ def test_when_accepts_nested_attributes_for_is_used_in_both_associated_models | |
+ m = Man.first | |
+ m.class_eval "accepts_nested_attributes_for :face" | |
+ f = Face.new(:description => "haunted") | |
+ f.class_eval "accepts_nested_attributes_for :man" | |
+ assert_nothing_raised do | |
+ m.face = f | |
+ assert m.save! | |
+ end | |
+ end | |
end | |
class InverseHasManyTests < ActiveRecord::TestCase | |
- fixtures :men, :interests | |
+ fixtures :men, :interests, :pirates | |
def test_parent_instance_should_be_shared_with_every_child_on_find | |
m = men(:gordon) | |
@@ -262,6 +275,15 @@ class InverseHasManyTests < ActiveRecord::TestCase | |
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error | |
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.find(:first).secret_interests } | |
end | |
+ | |
+ def test_when_accepts_nested_attributes_for_is_used_in_both_associated_models | |
+ pirate = DestructivePirate.first | |
+ cottons_parrot = LiveBird.new(:name => "Cotton's parrot") | |
+ assert_nothing_raised do | |
+ pirate.live_birds << cottons_parrot | |
+ assert pirate.save! | |
+ end | |
+ end | |
end | |
class InverseBelongsToTests < ActiveRecord::TestCase | |
diff --git a/activerecord/test/models/bird.rb b/activerecord/test/models/bird.rb | |
index e61d48e..895327d 100644 | |
--- a/activerecord/test/models/bird.rb | |
+++ b/activerecord/test/models/bird.rb | |
@@ -6,4 +6,9 @@ class Bird < ActiveRecord::Base | |
def cancel_save_callback_method | |
false | |
end | |
-end | |
\ No newline at end of file | |
+end | |
+ | |
+class LiveBird < Bird | |
+ belongs_to :destructive_pirate, :foreign_key => "pirate_id", :inverse_of => :live_birds | |
+ accepts_nested_attributes_for :destructive_pirate | |
+end | |
\ No newline at end of file | |
diff --git a/activerecord/test/models/pirate.rb b/activerecord/test/models/pirate.rb | |
index 0d3f62b..98ec7e2 100644 | |
--- a/activerecord/test/models/pirate.rb | |
+++ b/activerecord/test/models/pirate.rb | |
@@ -83,4 +83,6 @@ end | |
class DestructivePirate < Pirate | |
has_one :dependent_ship, :class_name => 'Ship', :foreign_key => :pirate_id, :dependent => :destroy | |
+ has_many :live_birds, :foreign_key => :bird_id, :inverse_of => :destructive_pirate | |
+ accepts_nested_attributes_for :live_birds | |
end | |
-- | |
1.6.6 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment