aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
diff options
context:
space:
mode:
authorMat Brown <mat@patch.com>2009-10-22 10:20:44 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2009-12-02 12:47:09 -0800
commit49e943c4f0ac3459bd53023167aaa08fc8e46733 (patch)
treecaf1d785fa27bdaf3ba7744842ba4b95d554d8c2 /activerecord/test/cases/associations/has_many_associations_test.rb
parent50c28e78c7aa40dc329facbe6131d657d5629bd4 (diff)
downloadrails-49e943c4f0ac3459bd53023167aaa08fc8e46733.tar.gz
rails-49e943c4f0ac3459bd53023167aaa08fc8e46733.tar.bz2
rails-49e943c4f0ac3459bd53023167aaa08fc8e46733.zip
Fix instance_eval calls to association proxies
In the current stable, ActiveRecord::Associations::AssociationProxy#method_missing calls yield() if a block is given, causing the block to always be evaluated in its calling context. However, in the case of instance_eval, correct behavior requires that the block be passed directly to the @target, rather than being evaluated inside a different block. Incidentally, this also simplifies the code slightly. [#3412 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 86d14c9c81..3c490c1eeb 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1178,5 +1178,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
client = firm.clients_using_primary_key.create!(:name => 'test')
assert_equal firm.name, client.firm_name
end
+
+ def test_normal_method_call_in_association_proxy
+ assert_equal 'Welcome to the weblog', Comment.all.map { |comment| comment.post }.first.title
+ end
+
+ def test_instance_eval_in_association_proxy
+ assert_equal 'Welcome to the weblog', Comment.all.map { |comment| comment.post }.first.instance_eval{title}
+ end
end