Skip to content

Commit

Permalink
Active Record: fix empty? on a relation with a group clause
Browse files Browse the repository at this point in the history
Fixes mislav#161, fixes mislav#167
  • Loading branch information
phene authored and mislav committed Sep 8, 2011
1 parent e1f4af7 commit 8ce2276
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/will_paginate/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ def size
# overloaded to be pagination-aware
def empty?
if !loaded? and offset_value
count <= offset_value
rel_count = count
if rel_count.respond_to?(:size) and !rel_count.is_a?(Integer)
rel_count.size <= offset_value
else
rel_count <= offset_value
end
else
super
end
Expand Down
7 changes: 7 additions & 0 deletions spec/finders/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@
topics.should_not be_empty
}.should run_queries(1)
end

it "support empty? for grouped queries" do
topics = Topic.group(:project_id).paginate :page => 1, :per_page => 3
lambda {
topics.should_not be_empty
}.should run_queries(1)
end

it "overrides total_entries count with a fixed value" do
lambda {
Expand Down

0 comments on commit 8ce2276

Please sign in to comment.