From 4b823633100c49c5ed52ee5a049de42aae58feb1 Mon Sep 17 00:00:00 2001 From: Ian White Date: Thu, 16 Oct 2008 11:34:15 +1100 Subject: [PATCH] Allow singleton methods sent to association proxy through (test and fix for bug introduced by 691aa20 [#1083]) --- .../associations/association_proxy.rb | 6 +++++- .../associations/has_many_associations_test.rb | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index d1a79df..8b0504d 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -145,7 +145,11 @@ module ActiveRecord super else load_target - @target.send(method, *args) + begin + @target.send(method, *args) + rescue NoMethodError + super + end end 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