aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-12-06 15:30:52 -0500
committerGitHub <noreply@github.com>2016-12-06 15:30:52 -0500
commit09b2e29fc602cedce6dc856ffeb5f8521c089aa5 (patch)
treecccf2d4f5586d94bec3d9bf70483b72661ae7be8 /activerecord/test/cases
parent91ae6e86da8174f5c4073bfce7fa6239464a4f02 (diff)
parente7f4c45bdc178c41face92e4be9ec027a07daeda (diff)
downloadrails-09b2e29fc602cedce6dc856ffeb5f8521c089aa5.tar.gz
rails-09b2e29fc602cedce6dc856ffeb5f8521c089aa5.tar.bz2
rails-09b2e29fc602cedce6dc856ffeb5f8521c089aa5.zip
Merge pull request #27251 from ebeigarts/fix-autosave
Fix association scope inside autosaved association callbacks
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/autosave_association_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb
index a3f82ed49d..77ee3ca2d7 100644
--- a/activerecord/test/cases/autosave_association_test.rb
+++ b/activerecord/test/cases/autosave_association_test.rb
@@ -1699,3 +1699,27 @@ class TestAutosaveAssociationWithTouch < ActiveRecord::TestCase
assert_nothing_raised { invoice.line_items.create(amount: 10) }
end
end
+
+class TestAutosaveAssociationOnAHasManyAssociationWithInverse < ActiveRecord::TestCase
+ class Post < ActiveRecord::Base
+ has_many :comments, inverse_of: :post
+ end
+
+ class Comment < ActiveRecord::Base
+ belongs_to :post, inverse_of: :comments
+
+ attr_accessor :post_comments_count
+ after_save do
+ self.post_comments_count = post.comments.count
+ end
+ end
+
+ def test_after_save_callback_with_autosave
+ post = Post.new(title: "Test", body: "...")
+ comment = post.comments.build(body: "...")
+ post.save!
+
+ assert_equal 1, post.comments.count
+ assert_equal 1, comment.post_comments_count
+ end
+end