aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-05-28 21:33:34 +0000
committerRick Olson <technoweenie@gmail.com>2006-05-28 21:33:34 +0000
commitea51d72edb36737445834777f06664096066a0ba (patch)
tree34924b8d0a41a652e5cc543e6f5b7f2afc0e1fe7 /activerecord/test
parent062845b4da06f7025d6190899cde25deb8eaac42 (diff)
downloadrails-ea51d72edb36737445834777f06664096066a0ba.tar.gz
rails-ea51d72edb36737445834777f06664096066a0ba.tar.bz2
rails-ea51d72edb36737445834777f06664096066a0ba.zip
Provide Association Extensions access to the instance that the association is being accessed from. Closes #4433 [josh@hasmanythrough.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4372 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/associations_test.rb23
-rw-r--r--activerecord/test/fixtures/author.rb11
2 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index c9a66f2efc..3667f71238 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -65,6 +65,29 @@ class AssociationsTest < Test::Unit::TestCase
end
end
+class AssociationProxyTest < Test::Unit::TestCase
+ fixtures :authors, :posts
+
+ def test_proxy_accessors
+ welcome = posts(:welcome)
+ assert_equal welcome, welcome.author.proxy_owner
+ assert_equal welcome.class.reflect_on_association(:author), welcome.author.proxy_reflection
+ welcome.author.class # force load target
+ assert_equal welcome.author, welcome.author.proxy_target
+
+ david = authors(:david)
+ assert_equal david, david.posts.proxy_owner
+ assert_equal david.class.reflect_on_association(:posts), david.posts.proxy_reflection
+ david.posts.first # force load target
+ assert_equal david.posts, david.posts.proxy_target
+
+ assert_equal david, david.posts_with_extension.testing_proxy_owner
+ assert_equal david.class.reflect_on_association(:posts_with_extension), david.posts_with_extension.testing_proxy_reflection
+ david.posts_with_extension.first # force load target
+ assert_equal david.posts_with_extension, david.posts_with_extension.testing_proxy_target
+ end
+end
+
class HasOneAssociationsTest < Test::Unit::TestCase
fixtures :accounts, :companies, :developers, :projects, :developers_projects
diff --git a/activerecord/test/fixtures/author.rb b/activerecord/test/fixtures/author.rb
index ec844f6238..a9102a269a 100644
--- a/activerecord/test/fixtures/author.rb
+++ b/activerecord/test/fixtures/author.rb
@@ -3,6 +3,17 @@ class Author < ActiveRecord::Base
has_many :posts_with_comments, :include => :comments, :class_name => "Post"
has_many :posts_with_categories, :include => :categories, :class_name => "Post"
has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post"
+ has_many :posts_with_extension, :class_name => "Post" do #, :extend => ProxyTestExtension
+ def testing_proxy_owner
+ proxy_owner
+ end
+ def testing_proxy_reflection
+ proxy_reflection
+ end
+ def testing_proxy_target
+ proxy_target
+ end
+ end
has_many :comments, :through => :posts
has_many :funky_comments, :through => :posts, :source => :comments