will_paginate 3.3.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -5
- data/lib/will_paginate/locale/en.yml +2 -0
- data/lib/will_paginate/version.rb +2 -2
- data/lib/will_paginate/view_helpers/action_view.rb +6 -2
- data/lib/will_paginate/view_helpers/link_renderer.rb +7 -5
- data/lib/will_paginate.rb +0 -12
- metadata +11 -47
- data/lib/will_paginate/data_mapper.rb +0 -100
- data/lib/will_paginate/view_helpers/merb.rb +0 -26
- data/spec/collection_spec.rb +0 -139
- data/spec/console +0 -12
- data/spec/console_fixtures.rb +0 -28
- data/spec/database.yml +0 -29
- data/spec/fake_rubygems.rb +0 -18
- data/spec/finders/active_record_spec.rb +0 -424
- data/spec/finders/activerecord_test_connector.rb +0 -140
- data/spec/finders/data_mapper_spec.rb +0 -114
- data/spec/finders/data_mapper_test_connector.rb +0 -54
- data/spec/finders/mongoid_spec.rb +0 -147
- data/spec/finders/sequel_spec.rb +0 -66
- data/spec/finders/sequel_test_connector.rb +0 -15
- data/spec/fixtures/admin.rb +0 -3
- data/spec/fixtures/developer.rb +0 -9
- data/spec/fixtures/developers_projects.yml +0 -13
- data/spec/fixtures/project.rb +0 -13
- data/spec/fixtures/projects.yml +0 -6
- data/spec/fixtures/replies.yml +0 -29
- data/spec/fixtures/reply.rb +0 -8
- data/spec/fixtures/schema.rb +0 -38
- data/spec/fixtures/topic.rb +0 -8
- data/spec/fixtures/topics.yml +0 -30
- data/spec/fixtures/user.rb +0 -2
- data/spec/fixtures/users.yml +0 -35
- data/spec/matchers/deprecation_matcher.rb +0 -27
- data/spec/matchers/phrase_matcher.rb +0 -19
- data/spec/matchers/query_count_matcher.rb +0 -36
- data/spec/page_number_spec.rb +0 -91
- data/spec/per_page_spec.rb +0 -41
- data/spec/spec_helper.rb +0 -46
- data/spec/view_helpers/action_view_spec.rb +0 -480
- data/spec/view_helpers/base_spec.rb +0 -143
- data/spec/view_helpers/link_renderer_base_spec.rb +0 -87
- data/spec/view_helpers/view_example_group.rb +0 -146
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'sqlite3'
|
2
|
-
require 'dm-core'
|
3
|
-
require 'dm-core/support/logger'
|
4
|
-
require 'dm-migrations'
|
5
|
-
|
6
|
-
DataMapper.setup :default, 'sqlite3::memory:'
|
7
|
-
|
8
|
-
# Define models
|
9
|
-
class Animal
|
10
|
-
include DataMapper::Resource
|
11
|
-
property :id, Serial
|
12
|
-
property :name, String
|
13
|
-
property :notes, Text
|
14
|
-
|
15
|
-
def self.setup
|
16
|
-
Animal.create(:name => 'Dog', :notes => "Man's best friend")
|
17
|
-
Animal.create(:name => 'Cat', :notes => "Woman's best friend")
|
18
|
-
Animal.create(:name => 'Lion', :notes => 'King of the Jungle')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Ownership
|
23
|
-
include DataMapper::Resource
|
24
|
-
|
25
|
-
belongs_to :animal, :key => true
|
26
|
-
belongs_to :human, :key => true
|
27
|
-
|
28
|
-
def self.setup
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class Human
|
33
|
-
include DataMapper::Resource
|
34
|
-
|
35
|
-
property :id, Serial
|
36
|
-
property :name, String
|
37
|
-
|
38
|
-
has n, :ownerships
|
39
|
-
has 1, :pet, :model => 'Animal', :through => :ownerships, :via => :animal
|
40
|
-
|
41
|
-
def self.setup
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Load fixtures
|
46
|
-
[Animal, Ownership, Human].each do |klass|
|
47
|
-
klass.auto_migrate!
|
48
|
-
klass.setup
|
49
|
-
end
|
50
|
-
|
51
|
-
if 'irb' == $0
|
52
|
-
DataMapper.logger.set_log($stdout, :debug)
|
53
|
-
DataMapper.logger.auto_flush = true
|
54
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if !ENV['SKIP_NONRAILS_TESTS']
|
4
|
-
if defined?(Rails)
|
5
|
-
old_rails = Rails
|
6
|
-
# Mongoid sees the `Rails` constant and then proceeds to `require "rails"`
|
7
|
-
# from its railtie. This tricks it into believing there is no Rails.
|
8
|
-
Object.send(:remove_const, :Rails)
|
9
|
-
end
|
10
|
-
require 'will_paginate/mongoid'
|
11
|
-
Object.send(:const_set, :Rails, old_rails) if old_rails
|
12
|
-
|
13
|
-
Mongo::Logger.logger.level = Logger::INFO
|
14
|
-
|
15
|
-
Mongoid.connect_to 'will_paginate_test'
|
16
|
-
class MongoidModel
|
17
|
-
include Mongoid::Document
|
18
|
-
end
|
19
|
-
|
20
|
-
mongoid_loaded = true
|
21
|
-
else
|
22
|
-
mongoid_loaded = false
|
23
|
-
end
|
24
|
-
|
25
|
-
describe WillPaginate::Mongoid do
|
26
|
-
before(:all) do
|
27
|
-
MongoidModel.delete_all
|
28
|
-
4.times { MongoidModel.create! }
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:criteria) { MongoidModel.criteria }
|
32
|
-
|
33
|
-
describe "#page" do
|
34
|
-
it "should forward to the paginate method" do
|
35
|
-
criteria.expects(:paginate).with(:page => 2).returns("itself")
|
36
|
-
criteria.page(2).should == "itself"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should not override per_page if set earlier in the chain" do
|
40
|
-
criteria.paginate(:per_page => 10).page(1).per_page.should == 10
|
41
|
-
criteria.paginate(:per_page => 20).page(1).per_page.should == 20
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#per_page" do
|
46
|
-
it "should set the limit if given an argument" do
|
47
|
-
criteria.per_page(10).options[:limit].should == 10
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should return the current limit if no argument is given" do
|
51
|
-
criteria.per_page.should == nil
|
52
|
-
criteria.per_page(10).per_page.should == 10
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should be interchangable with limit" do
|
56
|
-
criteria.limit(15).per_page.should == 15
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should be nil'able" do
|
60
|
-
criteria.per_page(nil).per_page.should be_nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "#paginate" do
|
65
|
-
it "should use criteria" do
|
66
|
-
criteria.paginate.should be_instance_of(::Mongoid::Criteria)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should not override page number if set earlier in the chain" do
|
70
|
-
criteria.page(3).paginate.current_page.should == 3
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should limit according to per_page parameter" do
|
74
|
-
criteria.paginate(:per_page => 10).options.should include(:limit => 10)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should skip according to page and per_page parameters" do
|
78
|
-
criteria.paginate(:page => 2, :per_page => 5).options.should include(:skip => 5)
|
79
|
-
end
|
80
|
-
|
81
|
-
specify "first fallback value for per_page option is the current limit" do
|
82
|
-
criteria.limit(12).paginate.options.should include(:limit => 12)
|
83
|
-
end
|
84
|
-
|
85
|
-
specify "second fallback value for per_page option is WillPaginate.per_page" do
|
86
|
-
criteria.paginate.options.should include(:limit => WillPaginate.per_page)
|
87
|
-
end
|
88
|
-
|
89
|
-
specify "page should default to 1" do
|
90
|
-
criteria.paginate.options.should include(:skip => 0)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should convert strings to integers" do
|
94
|
-
criteria.paginate(:page => "2", :per_page => "3").options.should include(:limit => 3)
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "collection compatibility" do
|
98
|
-
describe "#total_count" do
|
99
|
-
it "should be calculated correctly" do
|
100
|
-
criteria.paginate(:per_page => 1).total_entries.should == 4
|
101
|
-
criteria.paginate(:per_page => 3).total_entries.should == 4
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should be cached" do
|
105
|
-
criteria.expects(:count).once.returns(123)
|
106
|
-
criteria.paginate
|
107
|
-
2.times { criteria.total_entries.should == 123 }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should calculate total_pages" do
|
112
|
-
criteria.paginate(:per_page => 1).total_pages.should == 4
|
113
|
-
criteria.paginate(:per_page => 3).total_pages.should == 2
|
114
|
-
criteria.paginate(:per_page => 10).total_pages.should == 1
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should return per_page" do
|
118
|
-
criteria.paginate(:per_page => 1).per_page.should == 1
|
119
|
-
criteria.paginate(:per_page => 5).per_page.should == 5
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "#current_page" do
|
123
|
-
it "should return current_page" do
|
124
|
-
criteria.paginate(:page => 1).current_page.should == 1
|
125
|
-
criteria.paginate(:page => 3).current_page.should == 3
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should be casted to PageNumber" do
|
129
|
-
page = criteria.paginate(:page => 1).current_page
|
130
|
-
(page.instance_of? WillPaginate::PageNumber).should be
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should return offset" do
|
135
|
-
criteria.paginate(:page => 1).offset.should == 0
|
136
|
-
criteria.paginate(:page => 2, :per_page => 5).offset.should == 5
|
137
|
-
criteria.paginate(:page => 3, :per_page => 10).offset.should == 20
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should not pollute plain mongoid criterias" do
|
141
|
-
%w(total_entries total_pages current_page).each do |method|
|
142
|
-
criteria.should_not respond_to(method)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end if mongoid_loaded
|
data/spec/finders/sequel_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if !ENV['SKIP_NONRAILS_TESTS']
|
4
|
-
require 'will_paginate/sequel'
|
5
|
-
require File.expand_path('../sequel_test_connector', __FILE__)
|
6
|
-
sequel_loaded = true
|
7
|
-
else
|
8
|
-
sequel_loaded = false
|
9
|
-
end
|
10
|
-
|
11
|
-
describe Sequel::Dataset::Pagination, 'extension' do
|
12
|
-
|
13
|
-
class Car < Sequel::Model
|
14
|
-
self.dataset = dataset.extension(:pagination)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should have the #paginate method" do
|
18
|
-
Car.dataset.should respond_to(:paginate)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should NOT have the #paginate_by_sql method" do
|
22
|
-
Car.dataset.should_not respond_to(:paginate_by_sql)
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'pagination' do
|
26
|
-
before(:all) do
|
27
|
-
Car.create(:name => 'Shelby', :notes => "Man's best friend")
|
28
|
-
Car.create(:name => 'Aston Martin', :notes => "Woman's best friend")
|
29
|
-
Car.create(:name => 'Corvette', :notes => 'King of the Jungle')
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should imitate WillPaginate::Collection" do
|
33
|
-
result = Car.dataset.paginate(1, 2)
|
34
|
-
|
35
|
-
result.should_not be_empty
|
36
|
-
result.size.should == 2
|
37
|
-
result.length.should == 2
|
38
|
-
result.total_entries.should == 3
|
39
|
-
result.total_pages.should == 2
|
40
|
-
result.per_page.should == 2
|
41
|
-
result.current_page.should == 1
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should perform" do
|
45
|
-
Car.dataset.paginate(1, 2).all.should == [Car[1], Car[2]]
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should be empty" do
|
49
|
-
result = Car.dataset.paginate(3, 2)
|
50
|
-
result.should be_empty
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should perform with #select and #order" do
|
54
|
-
result = Car.select(Sequel.lit("name as foo")).order(:name).paginate(1, 2).all
|
55
|
-
result.size.should == 2
|
56
|
-
result.first.values[:foo].should == "Aston Martin"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should perform with #filter" do
|
60
|
-
results = Car.filter(:name => 'Shelby').paginate(1, 2).all
|
61
|
-
results.size.should == 1
|
62
|
-
results.first.should == Car.find(:name => 'Shelby')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
end if sequel_loaded
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'sequel'
|
2
|
-
|
3
|
-
Symbol.class_eval do
|
4
|
-
# Active Record calculations tries `as` on some objects but chokes when that
|
5
|
-
# object was a Symbol and it gets a Sequel::SQL::AliasedExpression.
|
6
|
-
undef as if method_defined? :as
|
7
|
-
end
|
8
|
-
|
9
|
-
db = Sequel.sqlite
|
10
|
-
|
11
|
-
db.create_table :cars do
|
12
|
-
primary_key :id, :integer, :auto_increment => true
|
13
|
-
column :name, :text
|
14
|
-
column :notes, :text
|
15
|
-
end
|
data/spec/fixtures/admin.rb
DELETED
data/spec/fixtures/developer.rb
DELETED
data/spec/fixtures/project.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class Project < ActiveRecord::Base
|
2
|
-
has_and_belongs_to_many :developers, :join_table => 'developers_projects'
|
3
|
-
|
4
|
-
has_many :topics
|
5
|
-
# :finder_sql => 'SELECT * FROM topics WHERE (topics.project_id = #{id})',
|
6
|
-
# :counter_sql => 'SELECT COUNT(*) FROM topics WHERE (topics.project_id = #{id})'
|
7
|
-
|
8
|
-
has_many :replies, :through => :topics do
|
9
|
-
def only_recent(params = {})
|
10
|
-
where(['replies.created_at > ?', 15.minutes.ago])
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/spec/fixtures/projects.yml
DELETED
data/spec/fixtures/replies.yml
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
witty_retort:
|
2
|
-
id: 1
|
3
|
-
topic_id: 1
|
4
|
-
content: Birdman is better!
|
5
|
-
created_at: <%= 6.hours.ago.utc.to_s(:db) %>
|
6
|
-
|
7
|
-
another:
|
8
|
-
id: 2
|
9
|
-
topic_id: 2
|
10
|
-
content: Nuh uh!
|
11
|
-
created_at: <%= 1.hour.ago.utc.to_s(:db) %>
|
12
|
-
|
13
|
-
spam:
|
14
|
-
id: 3
|
15
|
-
topic_id: 1
|
16
|
-
content: Nice site!
|
17
|
-
created_at: <%= 1.hour.ago.utc.to_s(:db) %>
|
18
|
-
|
19
|
-
decisive:
|
20
|
-
id: 4
|
21
|
-
topic_id: 4
|
22
|
-
content: "I'm getting to the bottom of this"
|
23
|
-
created_at: <%= 30.minutes.ago.utc.to_s(:db) %>
|
24
|
-
|
25
|
-
brave:
|
26
|
-
id: 5
|
27
|
-
topic_id: 4
|
28
|
-
content: "AR doesn't scare me a bit"
|
29
|
-
created_at: <%= 10.minutes.ago.utc.to_s(:db) %>
|
data/spec/fixtures/reply.rb
DELETED
data/spec/fixtures/schema.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
|
3
|
-
create_table "users", :force => true do |t|
|
4
|
-
t.column "name", :text
|
5
|
-
t.column "salary", :integer, :default => 70000
|
6
|
-
t.column "created_at", :datetime
|
7
|
-
t.column "updated_at", :datetime
|
8
|
-
t.column "type", :text
|
9
|
-
end
|
10
|
-
|
11
|
-
create_table "projects", :force => true do |t|
|
12
|
-
t.column "name", :text
|
13
|
-
end
|
14
|
-
|
15
|
-
create_table "developers_projects", :id => false, :force => true do |t|
|
16
|
-
t.column "developer_id", :integer, :null => false
|
17
|
-
t.column "project_id", :integer, :null => false
|
18
|
-
t.column "joined_on", :date
|
19
|
-
t.column "access_level", :integer, :default => 1
|
20
|
-
end
|
21
|
-
|
22
|
-
create_table "topics", :force => true do |t|
|
23
|
-
t.column "project_id", :integer
|
24
|
-
t.column "title", :string
|
25
|
-
t.column "subtitle", :string
|
26
|
-
t.column "content", :text
|
27
|
-
t.column "created_at", :datetime
|
28
|
-
t.column "updated_at", :datetime
|
29
|
-
end
|
30
|
-
|
31
|
-
create_table "replies", :force => true do |t|
|
32
|
-
t.column "content", :text
|
33
|
-
t.column "created_at", :datetime
|
34
|
-
t.column "updated_at", :datetime
|
35
|
-
t.column "topic_id", :integer
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/spec/fixtures/topic.rb
DELETED
data/spec/fixtures/topics.yml
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
futurama:
|
2
|
-
id: 1
|
3
|
-
title: Isnt futurama awesome?
|
4
|
-
subtitle: It really is, isnt it.
|
5
|
-
content: I like futurama
|
6
|
-
created_at: <%= 1.day.ago.utc.to_s(:db) %>
|
7
|
-
updated_at:
|
8
|
-
|
9
|
-
harvey_birdman:
|
10
|
-
id: 2
|
11
|
-
title: Harvey Birdman is the king of all men
|
12
|
-
subtitle: yup
|
13
|
-
content: He really is
|
14
|
-
created_at: <%= 2.hours.ago.utc.to_s(:db) %>
|
15
|
-
updated_at:
|
16
|
-
|
17
|
-
rails:
|
18
|
-
id: 3
|
19
|
-
project_id: 1
|
20
|
-
title: Rails is nice
|
21
|
-
subtitle: It makes me happy
|
22
|
-
content: except when I have to hack internals to fix pagination. even then really.
|
23
|
-
created_at: <%= 20.minutes.ago.utc.to_s(:db) %>
|
24
|
-
|
25
|
-
ar:
|
26
|
-
id: 4
|
27
|
-
project_id: 1
|
28
|
-
title: ActiveRecord sometimes freaks me out
|
29
|
-
content: "I mean, what's the deal with eager loading?"
|
30
|
-
created_at: <%= 15.minutes.ago.utc.to_s(:db) %>
|
data/spec/fixtures/user.rb
DELETED
data/spec/fixtures/users.yml
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
david:
|
2
|
-
id: 1
|
3
|
-
name: David
|
4
|
-
salary: 80000
|
5
|
-
type: Developer
|
6
|
-
|
7
|
-
jamis:
|
8
|
-
id: 2
|
9
|
-
name: Jamis
|
10
|
-
salary: 150000
|
11
|
-
type: Developer
|
12
|
-
|
13
|
-
<% for digit in 3..10 %>
|
14
|
-
dev_<%= digit %>:
|
15
|
-
id: <%= digit %>
|
16
|
-
name: fixture_<%= digit %>
|
17
|
-
salary: 100000
|
18
|
-
type: Developer
|
19
|
-
<% end %>
|
20
|
-
|
21
|
-
poor_jamis:
|
22
|
-
id: 11
|
23
|
-
name: Jamis
|
24
|
-
salary: 9000
|
25
|
-
type: Developer
|
26
|
-
|
27
|
-
admin:
|
28
|
-
id: 12
|
29
|
-
name: admin
|
30
|
-
type: Admin
|
31
|
-
|
32
|
-
goofy:
|
33
|
-
id: 13
|
34
|
-
name: Goofy
|
35
|
-
type: Admin
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
|
3
|
-
class DeprecationMatcher
|
4
|
-
def initialize(message)
|
5
|
-
@message = message
|
6
|
-
end
|
7
|
-
|
8
|
-
def matches?(block)
|
9
|
-
@actual = hijack_stderr(&block)
|
10
|
-
PhraseMatcher.new("DEPRECATION WARNING: #{@message}").matches?(@actual)
|
11
|
-
end
|
12
|
-
|
13
|
-
def failure_message
|
14
|
-
"expected deprecation warning #{@message.inspect}, got #{@actual.inspect}"
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def hijack_stderr
|
20
|
-
err = $stderr
|
21
|
-
$stderr = StringIO.new
|
22
|
-
yield
|
23
|
-
$stderr.string.rstrip
|
24
|
-
ensure
|
25
|
-
$stderr = err
|
26
|
-
end
|
27
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class PhraseMatcher
|
2
|
-
def initialize(string)
|
3
|
-
@string = string
|
4
|
-
@pattern = /\b#{Regexp.escape string}\b/
|
5
|
-
end
|
6
|
-
|
7
|
-
def matches?(actual)
|
8
|
-
@actual = actual.to_s
|
9
|
-
@actual =~ @pattern
|
10
|
-
end
|
11
|
-
|
12
|
-
def failure_message
|
13
|
-
"expected #{@actual.inspect} to contain phrase #{@string.inspect}"
|
14
|
-
end
|
15
|
-
|
16
|
-
def negative_failure_message
|
17
|
-
"expected #{@actual.inspect} not to contain phrase #{@string.inspect}"
|
18
|
-
end
|
19
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
class QueryCountMatcher
|
2
|
-
def initialize(num)
|
3
|
-
@expected_count = num
|
4
|
-
end
|
5
|
-
|
6
|
-
def matches?(block)
|
7
|
-
run(block)
|
8
|
-
|
9
|
-
if @expected_count.respond_to? :include?
|
10
|
-
@expected_count.include? @count
|
11
|
-
else
|
12
|
-
@count == @expected_count
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def run(block)
|
17
|
-
$query_count = 0
|
18
|
-
$query_sql = []
|
19
|
-
block.call
|
20
|
-
ensure
|
21
|
-
@queries = $query_sql.dup
|
22
|
-
@count = $query_count
|
23
|
-
end
|
24
|
-
|
25
|
-
def performed_queries
|
26
|
-
@queries
|
27
|
-
end
|
28
|
-
|
29
|
-
def failure_message
|
30
|
-
"expected #{@expected_count} queries, got #{@count}\n#{@queries.join("\n")}"
|
31
|
-
end
|
32
|
-
|
33
|
-
def negative_failure_message
|
34
|
-
"expected query count not to be #{@expected_count}"
|
35
|
-
end
|
36
|
-
end
|
data/spec/page_number_spec.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'will_paginate/page_number'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
describe WillPaginate::PageNumber do
|
6
|
-
describe "valid" do
|
7
|
-
def num
|
8
|
-
WillPaginate::PageNumber.new('12', 'page')
|
9
|
-
end
|
10
|
-
|
11
|
-
it "== 12" do
|
12
|
-
num.should eq(12)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "inspects to 'page 12'" do
|
16
|
-
num.inspect.should eq('page 12')
|
17
|
-
end
|
18
|
-
|
19
|
-
it "is a PageNumber" do
|
20
|
-
(num.instance_of? WillPaginate::PageNumber).should be
|
21
|
-
end
|
22
|
-
|
23
|
-
it "is a kind of Numeric" do
|
24
|
-
(num.is_a? Numeric).should be
|
25
|
-
end
|
26
|
-
|
27
|
-
it "is a kind of Integer" do
|
28
|
-
(num.is_a? Integer).should be
|
29
|
-
end
|
30
|
-
|
31
|
-
it "isn't directly a Integer" do
|
32
|
-
(num.instance_of? Integer).should_not be
|
33
|
-
end
|
34
|
-
|
35
|
-
it "passes the PageNumber=== type check" do |variable|
|
36
|
-
(WillPaginate::PageNumber === num).should be
|
37
|
-
end
|
38
|
-
|
39
|
-
it "passes the Numeric=== type check" do |variable|
|
40
|
-
(Numeric === num).should be
|
41
|
-
end
|
42
|
-
|
43
|
-
it "fails the Numeric=== type check" do |variable|
|
44
|
-
(Integer === num).should_not be
|
45
|
-
end
|
46
|
-
|
47
|
-
it "serializes as JSON number" do
|
48
|
-
JSON.dump(page: num).should eq('{"page":12}')
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "invalid" do
|
53
|
-
def create(value, name = 'page')
|
54
|
-
described_class.new(value, name)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "errors out on non-int values" do
|
58
|
-
lambda { create(nil) }.should raise_error(WillPaginate::InvalidPage)
|
59
|
-
lambda { create('') }.should raise_error(WillPaginate::InvalidPage)
|
60
|
-
lambda { create('Schnitzel') }.should raise_error(WillPaginate::InvalidPage)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "errors out on zero or less" do
|
64
|
-
lambda { create(0) }.should raise_error(WillPaginate::InvalidPage)
|
65
|
-
lambda { create(-1) }.should raise_error(WillPaginate::InvalidPage)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "doesn't error out on zero for 'offset'" do
|
69
|
-
lambda { create(0, 'offset') }.should_not raise_error
|
70
|
-
lambda { create(-1, 'offset') }.should raise_error(WillPaginate::InvalidPage)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "coercion method" do
|
75
|
-
it "defaults to 'page' name" do
|
76
|
-
num = WillPaginate::PageNumber(12)
|
77
|
-
num.inspect.should eq('page 12')
|
78
|
-
end
|
79
|
-
|
80
|
-
it "accepts a custom name" do
|
81
|
-
num = WillPaginate::PageNumber(12, 'monkeys')
|
82
|
-
num.inspect.should eq('monkeys 12')
|
83
|
-
end
|
84
|
-
|
85
|
-
it "doesn't affect PageNumber instances" do
|
86
|
-
num = WillPaginate::PageNumber(12)
|
87
|
-
num2 = WillPaginate::PageNumber(num)
|
88
|
-
num2.object_id.should eq(num.object_id)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|