提交 3e541799 编写于 作者: J Jon Leighton

Merge pull request #6134 from carlosantoniodasilva/ar-relation-kernel-private-methods

Fix issue with private kernel methods and collection associations
......@@ -81,7 +81,7 @@ def respond_to?(name, include_private = false)
def method_missing(method, *args, &block)
match = DynamicFinderMatch.match(method)
if match && match.instantiator?
send(:find_or_instantiator_by_attributes, match, match.attribute_names, *args) do |r|
scoped.send(:find_or_instantiator_by_attributes, match, match.attribute_names, *args) do |r|
proxy_association.send :set_owner_attributes, r
proxy_association.send :add_to_target, r
yield(r) if block_given?
......@@ -101,7 +101,7 @@ def method_missing(method, *args, &block)
end
else
scoped.readonly(nil).send(method, *args, &block)
scoped.readonly(nil).public_send(method, *args, &block)
end
end
......
......@@ -1703,4 +1703,9 @@ def test_building_has_many_association_with_restrict_dependency
ensure
ActiveRecord::Base.dependent_restrict_raises = option_before
end
def test_collection_association_with_private_kernel_method
firm = companies(:first_firm)
assert_equal [accounts(:signals37)], firm.accounts.open
end
end
......@@ -198,6 +198,11 @@ def self.destroyed_account_ids
@destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] }
end
# Test private kernel method through collection proxy using has_many.
def self.open
where('firm_name = ?', '37signals')
end
before_destroy do |account|
if account.firm
Account.destroyed_account_ids[account.firm.id] << account.id
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册