未验证 提交 bbee1c00 编写于 作者: K Kasper Timm Hansen 提交者: Rafael Mendonça França

Merge pull request #28474 from kamipo/fix_extension_with_darty_target

Fix extension method with dirty target in has_many associations
上级 b4895851
......@@ -1154,8 +1154,9 @@ def respond_to_missing?(method, _)
end
def method_missing(method, *args, &block)
if scope.respond_to?(method)
scope.public_send(method, *args, &block)
if scope.respond_to?(method) && scope.extending_values.any?
extend(*scope.extending_values)
public_send(method, *args, &block)
else
super
end
......
......@@ -36,6 +36,11 @@ def test_extension_with_scopes
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
......
......@@ -59,6 +59,10 @@ def newest
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册