aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-11-29 15:30:45 -0700
committerSean Griffin <sean@seantheprogrammer.com>2015-11-29 15:30:45 -0700
commit3f16a098452ee5d447142bd9a6f6045cb1fc83b4 (patch)
tree198bf133418ef4a5b25453fe8f3262017fe4add5 /activerecord/test
parentac26573c6609906c8d5f626e8e17078372cbd0df (diff)
parent6d0d83a33f59d9415685852cf77818c41e2e2700 (diff)
downloadrails-3f16a098452ee5d447142bd9a6f6045cb1fc83b4.tar.gz
rails-3f16a098452ee5d447142bd9a6f6045cb1fc83b4.tar.bz2
rails-3f16a098452ee5d447142bd9a6f6045cb1fc83b4.zip
Merge pull request #18155 from bogdan/collection_association_double_element_fix
Bugfix collection association #create method
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb6
-rw-r--r--activerecord/test/models/bulb.rb6
2 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 50ca6537cc..ad157582a4 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -2348,6 +2348,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal [first_bulb, second_bulb], car.bulbs
end
+ test 'double insertion of new object to association when same association used in the after create callback of a new object' do
+ car = Car.create!
+ car.bulbs << TrickyBulb.new
+ assert_equal 1, car.bulbs.size
+ end
+
def test_association_force_reload_with_only_true_is_deprecated
company = Company.find(1)
diff --git a/activerecord/test/models/bulb.rb b/activerecord/test/models/bulb.rb
index c1e491e5c5..dc0296305a 100644
--- a/activerecord/test/models/bulb.rb
+++ b/activerecord/test/models/bulb.rb
@@ -50,3 +50,9 @@ class FailedBulb < Bulb
throw(:abort)
end
end
+
+class TrickyBulb < Bulb
+ after_create do |record|
+ record.car.bulbs.to_a
+ end
+end