Skip to content

Commit

Permalink
Active Record: fix paginate_by_sql(:page => nil)
Browse files Browse the repository at this point in the history
Closes #187
  • Loading branch information
mislav committed Sep 27, 2011
1 parent 4a51ca4 commit 9bd5aec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/will_paginate/active_record.rb
Expand Up @@ -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]

Expand Down
7 changes: 7 additions & 0 deletions spec/finders/active_record_spec.rb
Expand Up @@ -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"
Expand Down

0 comments on commit 9bd5aec

Please sign in to comment.