Skip to content

Commit

Permalink
enable use of Sequel datasets with page_entries_info helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Aug 4, 2011
1 parent 3a246ba commit 3a3e07c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/will_paginate/sequel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def per_page
page_size
end

def size
current_page_record_count
end
alias length size

def total_entries
pagination_record_count
end
Expand Down
2 changes: 2 additions & 0 deletions spec/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
opts = %w[ --simple-prompt -rirb/completion ]
if ARGV.include? '-dm'
opts << '-rwill_paginate/data_mapper' << '-rfinders/data_mapper_test_connector'
elsif ARGV.include? '-seq'
opts << '-rwill_paginate/sequel' << '-rfinders/sequel_test_connector'
else
opts << '-rconsole_fixtures'
end
Expand Down
8 changes: 8 additions & 0 deletions spec/finders/sequel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Car < Sequel::Model
it "should imitate WillPaginate::Collection" do
result = Car.paginate(1, 2)

result.should_not be_empty
result.size.should == 2
result.length.should == 2
result.total_entries.should == 3
result.total_pages.should == 2
result.per_page.should == 2
Expand All @@ -42,6 +45,11 @@ class Car < Sequel::Model
it "should perform" do
Car.paginate(1, 2).all.should == [Car[1], Car[2]]
end

it "should be empty" do
result = Car.paginate(3, 2)
result.should be_empty
end

it "should perform with #select and #order" do
result = Car.select("name as foo".lit).order(:name).paginate(1, 2).all
Expand Down

0 comments on commit 3a3e07c

Please sign in to comment.