diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-03-20 19:32:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-20 19:32:07 +0100 |
commit | dd40c770532f48bb3a4e607ee9d8497aef533a74 (patch) | |
tree | 1af58bf5ed7db4b149486283689d73bd06111dfa /activerecord/test | |
parent | eeb8c3c246bd0c8bbf95b555efcec9fcb19cc3c6 (diff) | |
parent | 1385a8b5ff81adc3dfa5dc6ad88ce00b28e95ce1 (diff) | |
download | rails-dd40c770532f48bb3a4e607ee9d8497aef533a74.tar.gz rails-dd40c770532f48bb3a4e607ee9d8497aef533a74.tar.bz2 rails-dd40c770532f48bb3a4e607ee9d8497aef533a74.zip |
Merge pull request #28474 from kamipo/fix_extension_with_darty_target
Fix extension method with dirty target in has_many associations
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/extension_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 4 |
2 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/extension_test.rb b/activerecord/test/cases/associations/extension_test.rb index 974a3080d4..87d842f21d 100644 --- a/activerecord/test/cases/associations/extension_test.rb +++ b/activerecord/test/cases/associations/extension_test.rb @@ -36,6 +36,11 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase assert_equal comments(:greetings), posts(:welcome).comments.not_again.find_most_recent end + def test_extension_with_dirty_target + comment = posts(:welcome).comments.build(body: "New comment") + assert_equal comment, posts(:welcome).comments.with_content("New comment") + end + def test_marshalling_extensions david = developers(:david) assert_equal projects(:action_controller), david.projects.find_most_recent diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index e74aedb814..a2028b3eb9 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -59,6 +59,10 @@ class Post < ActiveRecord::Base def the_association proxy_association end + + def with_content(content) + self.detect { |comment| comment.body == content } + end end has_many :comments_with_extend, extend: NamedExtension, class_name: "Comment", foreign_key: "post_id" do |