diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-10-13 13:18:38 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-10-13 13:18:38 -0300 |
commit | 3c3a344aecba871ab9335dee7eee077dea1bce20 (patch) | |
tree | e50c7b791cabc8a6108143245bc8e3253b2ef6cc /activerecord/test | |
parent | d02adfaa4d04754e5c892e82f7cdbb5815cd66e1 (diff) | |
parent | 719d52db42a0eeebf0f1fa2f8ac3173544dd521e (diff) | |
download | rails-3c3a344aecba871ab9335dee7eee077dea1bce20.tar.gz rails-3c3a344aecba871ab9335dee7eee077dea1bce20.tar.bz2 rails-3c3a344aecba871ab9335dee7eee077dea1bce20.zip |
Merge pull request #17232 from Agis-/issue-17209
Autosave callbacks shouldn't be `after_save` callbacks
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/autosave_association_test.rb | 9 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb index b2a7d3956d..734fd5fe18 100644 --- a/activerecord/test/cases/autosave_association_test.rb +++ b/activerecord/test/cases/autosave_association_test.rb @@ -1,5 +1,6 @@ require 'cases/helper' require 'models/bird' +require 'models/comment' require 'models/company' require 'models/customer' require 'models/developer' @@ -616,6 +617,14 @@ class TestDefaultAutosaveAssociationOnNewRecord < ActiveRecord::TestCase firm.save! assert !account.persisted? end + + def test_autosave_new_record_with_after_create_callback + post = PostWithAfterCreateCallback.new(title: 'Captain Murphy', body: 'is back') + post.comments.build(body: 'foo') + post.save! + + assert_not_nil post.author_id + end end class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 256b720c9a..67027cbc22 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -219,6 +219,15 @@ class PostThatLoadsCommentsInAnAfterSaveHook < ActiveRecord::Base end end +class PostWithAfterCreateCallback < ActiveRecord::Base + self.table_name = 'posts' + has_many :comments, foreign_key: :post_id + + after_create do |post| + update_attribute(:author_id, comments.first.id) + end +end + class PostWithCommentWithDefaultScopeReferencesAssociation < ActiveRecord::Base self.table_name = 'posts' has_many :comment_with_default_scope_references_associations, foreign_key: :post_id |