提交 47779e75 编写于 作者: R Ryuta Kamizono

Support kwargs for named scopes

We fixed `generate_relation_method` to address kwargs warnings at
#38038, but I missed generated named scopes also need the same fix.

Test case has picked from #39196.
Co-authored-by: NJohn Hawthorn <john@hawthorn.email>
上级 56f30962
......@@ -195,6 +195,7 @@ def scope(name, body, &block)
scope
end
end
singleton_class.send(:ruby2_keywords, name) if respond_to?(:ruby2_keywords, true)
generate_relation_method(name)
end
......
......@@ -127,6 +127,18 @@ def test_scope_with_object
assert objects.all?(&:approved?), "all objects should be approved"
end
def test_scope_with_kwargs
# Explicit true
topics = Topic.with_kwargs(approved: true)
assert_operator topics.length, :>, 0
assert topics.all?(&:approved?), "all objects should be approved"
# No arguments
topics = Topic.with_kwargs()
assert_operator topics.length, :>, 0
assert topics.none?(&:approved?), "all objects should not be approved"
end
def test_has_many_associations_have_access_to_scopes
assert_not_equal Post.containing_the_letter_a, authors(:david).posts
assert_not_empty Post.containing_the_letter_a
......
......@@ -32,6 +32,8 @@ def call
end
}.new(self)
scope :with_kwargs, ->(approved: false) { where(approved: approved) }
module NamedExtension
def two
2
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册