Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add NamedScope#find_each tests [#2201 state:resolved]

  • Loading branch information...
commit 0b6f514947c38bf7af2b7e98905a49a94832e5f6 1 parent 0433348
@lifo lifo authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 activerecord/test/cases/named_scope_test.rb
View
16 activerecord/test/cases/named_scope_test.rb
@@ -15,7 +15,7 @@ def test_implements_enumerable
assert_equal Topic.find(:all), Topic.base
assert_equal Topic.find(:all), Topic.base.to_a
assert_equal Topic.find(:first), Topic.base.first
- assert_equal Topic.find(:all), Topic.base.each { |i| i }
+ assert_equal Topic.find(:all), Topic.base.map { |i| i }
end
def test_found_items_are_cached
@@ -316,6 +316,20 @@ def test_chaining_should_use_latest_conditions_when_searching
def test_methods_invoked_within_scopes_should_respect_scope
assert_equal [], Topic.approved.by_rejected_ids.proxy_options[:conditions][:id]
end
+
+ def test_named_scopes_batch_finders
+ assert_equal 3, Topic.approved.count
+
+ assert_queries(4) do
+ Topic.approved.find_each(:batch_size => 1) {|t| assert t.approved? }
+ end
+
+ assert_queries(3) do
+ Topic.approved.find_in_batches(:batch_size => 2) do |group|
+ group.each {|t| assert t.approved? }
+ end
+ end
+ end
end
class DynamicScopeMatchTest < ActiveRecord::TestCase
Please sign in to comment.
Something went wrong with that request. Please try again.