From 2ccab84d3af5c6c6f266b86df832b62e2f9680b2 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Wed, 7 Jul 2010 15:47:57 -0400 Subject: [PATCH] Fix the #using_limitable_reflections? helper to work correctly by not examining the length of an array which contains false/true, hence always passing. --- .../lib/active_record/relation/finder_methods.rb | 2 +- activerecord/test/cases/associations_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index f39951e..3bf4c5b 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -339,7 +339,7 @@ module ActiveRecord end def using_limitable_reflections?(reflections) - reflections.collect(&:collection?).length.zero? + reflections.none?(&:collection?) end end diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb index d99fb44..4ae776c 100644 --- a/activerecord/test/cases/associations_test.rb +++ b/activerecord/test/cases/associations_test.rb @@ -65,6 +65,16 @@ class AssociationsTest < ActiveRecord::TestCase assert_equal 1, firm.clients(true).size, "New firm should have reloaded clients count" end + def test_using_limitable_reflections_helper + using_limitable_reflections = lambda { |reflections| Tagging.scoped.send :using_limitable_reflections?, reflections } + belongs_to_reflections = [Tagging.reflect_on_association(:tag), Tagging.reflect_on_association(:super_tag)] + has_many_reflections = [Tag.reflect_on_association(:taggings), Developer.reflect_on_association(:projects)] + mixed_reflections = (belongs_to_reflections + has_many_reflections).uniq + assert using_limitable_reflections.call(belongs_to_reflections), "Belong to associations are limitable" + assert !using_limitable_reflections.call(has_many_reflections), "All has many style associations are not limitable" + assert !using_limitable_reflections.call(mixed_reflections), "No collection associations (has many style) should pass" + end + def test_force_reload_is_uncached firm = Firm.create!("name" => "A New Firm, Inc") client = Client.create!("name" => "TheClient.com", :firm => firm) -- 1.6.4.2