Permalink
Browse files

Fix the #using_limitable_reflections? helper to work correctly by not…

… examining the length of an array which contains false/true, hence always passing.

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 0963774 commit 504f7cfbb3d6fab0f2bacaad48e0301ae0976782 @metaskills metaskills committed with josevalim Jul 7, 2010
Showing with 11 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/associations.rb
  2. +10 −0 activerecord/test/cases/associations_test.rb
@@ -1782,7 +1782,7 @@ def references_eager_loaded_tables?(options)
end
def using_limitable_reflections?(reflections)
- reflections.collect(&:collection?).length.zero?
+ reflections.none?(&:collection?)
end
def column_aliases(join_dependency)
@@ -74,6 +74,16 @@ def test_force_reload_is_uncached
assert_queries(1) { assert_not_nil firm.clients(true).each {} }
end
end
+
+ def test_using_limitable_reflections_helper
+ using_limitable_reflections = lambda { |reflections| ActiveRecord::Base.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_storing_in_pstore
require "tmpdir"

0 comments on commit 504f7cf

Please sign in to comment.