diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index 056a294..f7ad8b7 100644 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -84,11 +84,18 @@ class AssociationsTest < ActiveRecord::TestCase assert_equal "Natural Company", db["apple"].clients.first.name end end + end class AssociationProxyTest < ActiveRecord::TestCase fixtures :authors, :posts, :categorizations, :categories, :developers, :projects, :developers_projects - + + def test_backtracking_scoped_association_proxy_chain + count_without_class_method = authors(:david).categorizations.find(:all).select {|cz| cz.category.categorizations.size > 1 }.size + count_with_class_method = authors(:david).categorizations.that_have_siblings_with_common_category_parent.size + assert_equal(count_without_class_method,count_with_class_method) + end + def test_proxy_accessors welcome = posts(:welcome) assert_equal welcome, welcome.author.proxy_owner diff --git a/activerecord/test/models/categorization.rb b/activerecord/test/models/categorization.rb index 1059432..1300f1e 100644 --- a/activerecord/test/models/categorization.rb +++ b/activerecord/test/models/categorization.rb @@ -2,4 +2,10 @@ class Categorization < ActiveRecord::Base belongs_to :post belongs_to :category belongs_to :author + + class << self + def that_have_siblings_with_common_category_parent + find(:all).select {|cz| cz.category.categorizations.size > 1 } + end + end end \ No newline at end of file