File: sequel_spec.rb

package info (click to toggle)
ruby-will-paginate 3.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: ruby: 2,940; sh: 50; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require_relative './spec_helper'
require 'sequel'
require 'will_paginate/sequel'

Sequel.sqlite.create_table :cars do
  primary_key :id, :integer, :auto_increment => true
  column :name, :text
  column :notes, :text
end

describe Sequel::Dataset::Pagination, 'extension' do

  class Car < Sequel::Model
    self.dataset = dataset.extension(:pagination)
  end

  it "should have the #paginate method" do
    Car.dataset.should respond_to(:paginate)
  end

  it "should NOT have the #paginate_by_sql method" do
    Car.dataset.should_not respond_to(:paginate_by_sql)
  end

  describe 'pagination' do
    before(:all) do
      Car.create(:name => 'Shelby', :notes => "Man's best friend")
      Car.create(:name => 'Aston Martin', :notes => "Woman's best friend")
      Car.create(:name => 'Corvette', :notes => 'King of the Jungle')
    end

    it "should imitate WillPaginate::Collection" do
      result = Car.dataset.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
      result.current_page.should == 1
    end
    
    it "should perform" do
      Car.dataset.paginate(1, 2).all.should == [Car[1], Car[2]]
    end

    it "should be empty" do
      result = Car.dataset.paginate(3, 2)
      result.should be_empty
    end
    
    it "should perform with #select and #order" do
      result = Car.select(Sequel.lit("name as foo")).order(:name).paginate(1, 2).all
      result.size.should == 2
      result.first.values[:foo].should == "Aston Martin"
    end

    it "should perform with #filter" do
      results = Car.filter(:name => 'Shelby').paginate(1, 2).all
      results.size.should == 1
      results.first.should == Car.find(:name => 'Shelby')
    end
  end

end