Fix for ActiveRecord::Relation#empty? when count is performed on a grouped query. #178

Closed
wants to merge 3 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+13 −1
Split
@@ -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
@@ -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 {