From 6841a555f2ce0762f44a2e3a2c4b58f8eabafdea Mon Sep 17 00:00:00 2001 From: Ian White Date: Thu, 16 Oct 2008 12:02:16 +1100 Subject: [PATCH] Allow class methods to be sent (via #send) to association proxy (test and fix for bug introduced by 691aa20 [#1083]) --- .../associations/association_collection.rb | 4 ++++ .../associations/has_many_associations_test.rb | 6 +++++- 2 files changed, 9 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 463de9d..212b0b6 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -320,6 +320,10 @@ module ActiveRecord exists?(record) end + def proxy_respond_to?(method) + super || @reflection.klass.respond_to?(method) + end + protected def construct_find_options!(options) end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 1bc9c39..c685fa1 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1079,6 +1079,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end end 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 + end end -- 1.6.0.1