From 238c80f97fcffa6d5995fed0831824e80299bdda Mon Sep 17 00:00:00 2001 From: Tom Meier Date: Mon, 7 Jun 2010 15:18:03 +1000 Subject: [PATCH] Allow send on association proxy references --- .../associations/association_proxy.rb | 4 ++-- activerecord/test/cases/associations_test.rb | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index e88618d..a9a4bce 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -144,12 +144,12 @@ module ActiveRecord @target.inspect end - def send(method, *args) + def send(method, *args, &block) if proxy_respond_to?(method) super else load_target - @target.send(method, *args) + @target.send(method, *args, &block) end end diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index d99fb44..245fbe7 100644 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -64,7 +64,7 @@ class AssociationsTest < ActiveRecord::TestCase assert !firm.clients(true).empty?, "New firm should have reloaded client objects" assert_equal 1, firm.clients(true).size, "New firm should have reloaded clients count" end - + def test_force_reload_is_uncached firm = Firm.create!("name" => "A New Firm, Inc") client = Client.create!("name" => "TheClient.com", :firm => firm) @@ -80,6 +80,15 @@ end class AssociationProxyTest < ActiveRecord::TestCase fixtures :authors, :posts, :categorizations, :categories, :developers, :projects, :developers_projects + def test_send_with_block + tom = Author.create(:name => "Tom") + p = Post.create(:title => "New on Edge", :body => "Allow me to iterate via send on association proxy!", :author => tom) + assert_equal tom.posts.size, 1 + counter = 0 + tom.posts.send(:each){ |post| counter += 1 } + assert_equal counter, 1 + end + def test_proxy_accessors welcome = posts(:welcome) assert_equal welcome, welcome.author.proxy_owner -- 1.6.5.5