Permalink
Browse files

enable use of Sequel datasets with `page_entries_info` helper

  • Loading branch information...
1 parent 3a246ba commit 3a3e07c729f0058f5de9fa64b27d21e303bcb865 @mislav committed Aug 4, 2011
Showing with 15 additions and 0 deletions.
  1. +5 −0 lib/will_paginate/sequel.rb
  2. +2 −0 spec/console
  3. +8 −0 spec/finders/sequel_spec.rb
View
5 lib/will_paginate/sequel.rb
@@ -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
View
2 spec/console
@@ -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
View
8 spec/finders/sequel_spec.rb
@@ -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
@@ -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

0 comments on commit 3a3e07c

Please sign in to comment.