From 3a3e07c729f0058f5de9fa64b27d21e303bcb865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohnic=CC=81?= Date: Thu, 4 Aug 2011 18:48:47 +0200 Subject: [PATCH] enable use of Sequel datasets with `page_entries_info` helper --- lib/will_paginate/sequel.rb | 5 +++++ spec/console | 2 ++ spec/finders/sequel_spec.rb | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/lib/will_paginate/sequel.rb b/lib/will_paginate/sequel.rb index 99a670c84..3fb740d1e 100644 --- a/lib/will_paginate/sequel.rb +++ b/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 diff --git a/spec/console b/spec/console index eae5da46d..4c64785b9 100755 --- a/spec/console +++ b/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 diff --git a/spec/finders/sequel_spec.rb b/spec/finders/sequel_spec.rb index c9abb6706..720c06ac1 100644 --- a/spec/finders/sequel_spec.rb +++ b/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