Skip to content
Browse files

Active Record: fix `paginate_by_sql(:page => nil)`

Closes #187
  • Loading branch information...
1 parent 4a51ca4 commit 9bd5aec3ddccfee211a2ef512148aaf8eeda9d5f @mislav committed Sep 27, 2011
Showing with 8 additions and 1 deletion.
  1. +1 −1 lib/will_paginate/active_record.rb
  2. +7 −0 spec/finders/active_record_spec.rb
View
2 lib/will_paginate/active_record.rb
@@ -167,7 +167,7 @@ module BaseMethods
# application.
#
def paginate_by_sql(sql, options)
- pagenum = options.fetch(:page) { raise ArgumentError, ":page parameter required" }
+ pagenum = options.fetch(:page) { raise ArgumentError, ":page parameter required" } || 1
per_page = options[:per_page] || self.per_page
total = options[:total_entries]
View
7 spec/finders/active_record_spec.rb
@@ -212,6 +212,13 @@
}.should run_queries(1)
end
+ it "defaults to page 1" do
+ sql = "select content from topics"
+ topics = Topic.paginate_by_sql sql, :page => nil, :per_page => 1
+ topics.current_page.should == 1
+ topics.size.should == 1
+ end
+
it "should strip the order when counting" do
lambda {
sql = "select id, title, content from topics order by title"

0 comments on commit 9bd5aec

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