Skip to content

Commit

Permalink
scoped paginated_each now yields the block in an exclusive scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Bielohlawek authored and mislav committed Oct 7, 2008
1 parent 39e77cf commit 068702d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/will_paginate/finder.rb
Expand Up @@ -104,7 +104,10 @@ def paginated_each(options = {}, &block)

begin
collection = paginate(options)
total += collection.each(&block).size
with_exclusive_scope(:find => {}) do
# using exclusive scope so that the block is yielded in scope-free context
total += collection.each(&block).size
end
options[:page] += 1
end until collection.size < collection.per_page

Expand Down
6 changes: 6 additions & 0 deletions test/finder_test.rb
Expand Up @@ -427,6 +427,12 @@ def test_paginated_each
assert_equal 14, Developer.paginated_each(:page => '2') { }
end

def test_paginated_each_with_named_scope
assert_equal 2, Developer.poor.paginated_each(:per_page => 1) {
assert_equal 11, Developer.count
}
end

# detect ActiveRecord 2.1
if ActiveRecord::Base.private_methods.include?('references_eager_loaded_tables?')
def test_removes_irrelevant_includes_in_count
Expand Down

0 comments on commit 068702d

Please sign in to comment.