mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure association proxy responds to private class methods defined in associated class. [#1083]
This commit is contained in:
parent
9cb5400871
commit
95c609357e
3 changed files with 18 additions and 4 deletions
|
@ -320,8 +320,8 @@ module ActiveRecord
|
|||
exists?(record)
|
||||
end
|
||||
|
||||
def proxy_respond_to?(method)
|
||||
super || @reflection.klass.respond_to?(method)
|
||||
def proxy_respond_to?(method, include_private = false)
|
||||
super || @reflection.klass.respond_to?(method, include_private)
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -1081,8 +1081,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_sending_new_to_association_proxy_should_have_same_effect_as_calling_new
|
||||
clients_assoc = companies(:first_firm).clients
|
||||
assert_equal clients_assoc.new.attributes, clients_assoc.send(:new).attributes
|
||||
client_association = companies(:first_firm).clients
|
||||
assert_equal client_association.new.attributes, client_association.send(:new).attributes
|
||||
end
|
||||
|
||||
def test_respond_to_private_class_methods
|
||||
client_association = companies(:first_firm).clients
|
||||
assert !client_association.respond_to?(:private_method)
|
||||
assert client_association.respond_to?(:private_method, true)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -112,6 +112,14 @@ class Client < Company
|
|||
def rating?
|
||||
query_attribute :rating
|
||||
end
|
||||
|
||||
class << self
|
||||
private
|
||||
|
||||
def private_method
|
||||
"darkness"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue