Skip to content
This repository
Browse code

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

… examining the length of an array which contains false/true, hence always passing. [#4869 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 0e9bc23c0e5dba228626ffbc2bef069331b2e471 1 parent 8b2330e
Ken Collins metaskills authored josevalim committed
2  activerecord/lib/active_record/relation/finder_methods.rb
@@ -339,7 +339,7 @@ def column_aliases(join_dependency)
339 339 end
340 340
341 341 def using_limitable_reflections?(reflections)
342   - reflections.collect(&:collection?).length.zero?
  342 + reflections.none?(&:collection?)
343 343 end
344 344
345 345 end
10 activerecord/test/cases/associations_test.rb
@@ -65,6 +65,16 @@ def test_force_reload
65 65 assert_equal 1, firm.clients(true).size, "New firm should have reloaded clients count"
66 66 end
67 67
  68 + def test_using_limitable_reflections_helper
  69 + using_limitable_reflections = lambda { |reflections| Tagging.scoped.send :using_limitable_reflections?, reflections }
  70 + belongs_to_reflections = [Tagging.reflect_on_association(:tag), Tagging.reflect_on_association(:super_tag)]
  71 + has_many_reflections = [Tag.reflect_on_association(:taggings), Developer.reflect_on_association(:projects)]
  72 + mixed_reflections = (belongs_to_reflections + has_many_reflections).uniq
  73 + assert using_limitable_reflections.call(belongs_to_reflections), "Belong to associations are limitable"
  74 + assert !using_limitable_reflections.call(has_many_reflections), "All has many style associations are not limitable"
  75 + assert !using_limitable_reflections.call(mixed_reflections), "No collection associations (has many style) should pass"
  76 + end
  77 +
68 78 def test_force_reload_is_uncached
69 79 firm = Firm.create!("name" => "A New Firm, Inc")
70 80 client = Client.create!("name" => "TheClient.com", :firm => firm)

0 comments on commit 0e9bc23

Please sign in to comment.
Something went wrong with that request. Please try again.