kaminari 0.17.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kaminari might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +26 -42
- data/CHANGELOG.md +579 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +1 -0
- data/README.md +545 -0
- data/Rakefile +21 -24
- data/gemfiles/active_record_41.gemfile +3 -4
- data/gemfiles/active_record_42.gemfile +3 -4
- data/gemfiles/active_record_50.gemfile +20 -0
- data/gemfiles/active_record_edge.gemfile +11 -7
- data/kaminari.gemspec +22 -26
- data/lib/kaminari.rb +4 -39
- data/lib/kaminari/version.rb +2 -1
- data/misc/bug_report_template.rb +57 -0
- metadata +45 -186
- data/.gemtest +0 -0
- data/.rspec +0 -2
- data/CHANGELOG.rdoc +0 -480
- data/README.rdoc +0 -336
- data/app/views/kaminari/_first_page.html.erb +0 -11
- data/app/views/kaminari/_first_page.html.haml +0 -9
- data/app/views/kaminari/_first_page.html.slim +0 -10
- data/app/views/kaminari/_gap.html.erb +0 -8
- data/app/views/kaminari/_gap.html.haml +0 -8
- data/app/views/kaminari/_gap.html.slim +0 -9
- data/app/views/kaminari/_last_page.html.erb +0 -11
- data/app/views/kaminari/_last_page.html.haml +0 -9
- data/app/views/kaminari/_last_page.html.slim +0 -10
- data/app/views/kaminari/_next_page.html.erb +0 -11
- data/app/views/kaminari/_next_page.html.haml +0 -9
- data/app/views/kaminari/_next_page.html.slim +0 -10
- data/app/views/kaminari/_page.html.erb +0 -12
- data/app/views/kaminari/_page.html.haml +0 -10
- data/app/views/kaminari/_page.html.slim +0 -11
- data/app/views/kaminari/_paginator.html.erb +0 -23
- data/app/views/kaminari/_paginator.html.haml +0 -18
- data/app/views/kaminari/_paginator.html.slim +0 -19
- data/app/views/kaminari/_prev_page.html.erb +0 -11
- data/app/views/kaminari/_prev_page.html.haml +0 -9
- data/app/views/kaminari/_prev_page.html.slim +0 -10
- data/config/locales/kaminari.yml +0 -19
- data/gemfiles/active_record_30.gemfile +0 -28
- data/gemfiles/active_record_31.gemfile +0 -26
- data/gemfiles/active_record_32.gemfile +0 -25
- data/gemfiles/active_record_40.gemfile +0 -26
- data/gemfiles/data_mapper_12.gemfile +0 -32
- data/gemfiles/mongo_mapper.gemfile +0 -25
- data/gemfiles/mongoid_30.gemfile +0 -22
- data/gemfiles/mongoid_31.gemfile +0 -21
- data/gemfiles/mongoid_40.gemfile +0 -19
- data/gemfiles/mongoid_50.gemfile +0 -23
- data/gemfiles/sinatra_13.gemfile +0 -36
- data/gemfiles/sinatra_14.gemfile +0 -33
- data/lib/generators/kaminari/config_generator.rb +0 -16
- data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
- data/lib/generators/kaminari/views_generator.rb +0 -119
- data/lib/kaminari/config.rb +0 -51
- data/lib/kaminari/engine.rb +0 -4
- data/lib/kaminari/grape.rb +0 -4
- data/lib/kaminari/helpers/action_view_extension.rb +0 -132
- data/lib/kaminari/helpers/paginator.rb +0 -195
- data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
- data/lib/kaminari/helpers/tags.rb +0 -108
- data/lib/kaminari/hooks.rb +0 -53
- data/lib/kaminari/models/active_record_extension.rb +0 -22
- data/lib/kaminari/models/active_record_model_extension.rb +0 -22
- data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
- data/lib/kaminari/models/array_extension.rb +0 -66
- data/lib/kaminari/models/configuration_methods.rb +0 -48
- data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
- data/lib/kaminari/models/data_mapper_extension.rb +0 -51
- data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
- data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
- data/lib/kaminari/models/mongoid_extension.rb +0 -26
- data/lib/kaminari/models/page_scope_methods.rb +0 -73
- data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
- data/lib/kaminari/railtie.rb +0 -7
- data/lib/kaminari/sinatra.rb +0 -7
- data/spec/config/config_spec.rb +0 -91
- data/spec/fake_app/active_record/config.rb +0 -3
- data/spec/fake_app/active_record/models.rb +0 -65
- data/spec/fake_app/data_mapper/config.rb +0 -1
- data/spec/fake_app/data_mapper/models.rb +0 -27
- data/spec/fake_app/mongo_mapper/config.rb +0 -2
- data/spec/fake_app/mongo_mapper/models.rb +0 -9
- data/spec/fake_app/mongoid/config.rb +0 -20
- data/spec/fake_app/mongoid/models.rb +0 -38
- data/spec/fake_app/rails_app.rb +0 -56
- data/spec/fake_app/sinatra_app.rb +0 -22
- data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
- data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
- data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
- data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
- data/spec/fake_gem.rb +0 -20
- data/spec/generators/views_generator_spec.rb +0 -18
- data/spec/helpers/action_view_extension_spec.rb +0 -318
- data/spec/helpers/helpers_spec.rb +0 -144
- data/spec/helpers/sinatra_helpers_spec.rb +0 -223
- data/spec/helpers/tags_spec.rb +0 -140
- data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
- data/spec/models/active_record/inherited_spec.rb +0 -9
- data/spec/models/active_record/scopes_spec.rb +0 -265
- data/spec/models/array_spec.rb +0 -172
- data/spec/models/configuration_methods_spec.rb +0 -125
- data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
- data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
- data/spec/models/mongoid/mongoid_spec.rb +0 -228
- data/spec/requests/users_spec.rb +0 -53
- data/spec/spec_helper.rb +0 -34
- data/spec/spec_helper_for_sinatra.rb +0 -34
- data/spec/support/database_cleaner.rb +0 -19
- data/spec/support/matchers.rb +0 -52
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if defined? ActiveRecord
|
4
|
-
describe Kaminari::ActiveRecordRelationMethods do
|
5
|
-
describe '#total_count' do
|
6
|
-
before do
|
7
|
-
@author = User.create! :name => 'author'
|
8
|
-
@author2 = User.create! :name => 'author2'
|
9
|
-
@author3 = User.create! :name => 'author3'
|
10
|
-
@books = 2.times.map {|i| @author.books_authored.create!(:title => "title%03d" % i) }
|
11
|
-
@books2 = 3.times.map {|i| @author2.books_authored.create!(:title => "title%03d" % i) }
|
12
|
-
@books3 = 4.times.map {|i| @author3.books_authored.create!(:title => "subject%03d" % i) }
|
13
|
-
@readers = 4.times.map { User.create! :name => 'reader' }
|
14
|
-
@books.each {|book| book.readers << @readers }
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when the scope is cloned" do
|
18
|
-
it "should reset total_coount momoization" do
|
19
|
-
User.page.tap(&:total_count).where(:name => 'author').total_count.should == 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when the scope includes an order which references a generated column" do
|
24
|
-
it "should successfully count the results" do
|
25
|
-
@author.readers.by_read_count.page(1).total_count.should == @readers.size
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when the scope use conditions on includes" do
|
30
|
-
it "should keep includes and successfully count the results" do
|
31
|
-
# Only @author and @author2 have books titled with the title00x partern
|
32
|
-
if ActiveRecord::VERSION::STRING >= "4.1.0"
|
33
|
-
User.includes(:books_authored).references(:books).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
|
34
|
-
else
|
35
|
-
User.includes(:books_authored).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when the Relation has custom select clause' do
|
41
|
-
specify do
|
42
|
-
lambda { User.select('*, 1 as one').page(1).total_count }.should_not raise_exception
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when total_count receives options" do
|
47
|
-
it "should return a distinct total count for rails < 4.1" do
|
48
|
-
if ActiveRecord::VERSION::STRING < "4.1.0"
|
49
|
-
User.page(1).total_count(:name, :distinct => true).should == 4
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should ignore the options for rails 4.1+" do
|
54
|
-
if ActiveRecord::VERSION::STRING >= "4.1.0"
|
55
|
-
User.page(1).total_count(:name, :distinct => true).should == 7
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
if ActiveRecord::VERSION::STRING < '4.1.0'
|
61
|
-
context 'when count receives options' do
|
62
|
-
it 'should return a distinct set by column for rails < 4.1' do
|
63
|
-
User.page(1).count(:name, :distinct => true).should == 4
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "when the scope returns an ActiveSupport::OrderedHash" do
|
69
|
-
it "should not throw exception by passing options to count" do
|
70
|
-
lambda {
|
71
|
-
@author.readers.by_read_count.page(1).total_count(:name, :distinct => true)
|
72
|
-
}.should_not raise_exception
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,265 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
if defined? ActiveRecord
|
4
|
-
|
5
|
-
describe Kaminari::ActiveRecordModelExtension do
|
6
|
-
before do
|
7
|
-
Kaminari.configure do |config|
|
8
|
-
config.page_method_name = :per_page_kaminari
|
9
|
-
end
|
10
|
-
class Comment < ActiveRecord::Base; end
|
11
|
-
end
|
12
|
-
|
13
|
-
subject { Comment }
|
14
|
-
it { should respond_to(:per_page_kaminari) }
|
15
|
-
it { should_not respond_to(:page) }
|
16
|
-
|
17
|
-
after do
|
18
|
-
Kaminari.configure do |config|
|
19
|
-
config.page_method_name = :page
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
shared_examples_for 'the first page' do
|
25
|
-
it { should have(25).users }
|
26
|
-
its('first.name') { should == 'user001' }
|
27
|
-
end
|
28
|
-
|
29
|
-
shared_examples_for 'blank page' do
|
30
|
-
it { should have(0).users }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe Kaminari::ActiveRecordExtension do
|
34
|
-
before :all do
|
35
|
-
[User, GemDefinedModel, Device].each do |m|
|
36
|
-
1.upto(100) {|i| m.create! :name => "user#{'%03d' % i}", :age => (i / 10)}
|
37
|
-
end
|
38
|
-
end
|
39
|
-
after :all do
|
40
|
-
[User, GemDefinedModel, Device].each {|m| m.delete_all }
|
41
|
-
end
|
42
|
-
|
43
|
-
[User, Admin, GemDefinedModel, Device].each do |model_class|
|
44
|
-
context "for #{model_class}" do
|
45
|
-
describe '#page' do
|
46
|
-
context 'page 1' do
|
47
|
-
subject { model_class.page 1 }
|
48
|
-
it_should_behave_like 'the first page'
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'page 2' do
|
52
|
-
subject { model_class.page 2 }
|
53
|
-
it { should have(25).users }
|
54
|
-
its('first.name') { should == 'user026' }
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'page without an argument' do
|
58
|
-
subject { model_class.page }
|
59
|
-
it_should_behave_like 'the first page'
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'page < 1' do
|
63
|
-
subject { model_class.page 0 }
|
64
|
-
it_should_behave_like 'the first page'
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'page > max page' do
|
68
|
-
subject { model_class.page 5 }
|
69
|
-
it_should_behave_like 'blank page'
|
70
|
-
end
|
71
|
-
|
72
|
-
describe 'ensure #order_values is preserved' do
|
73
|
-
subject { model_class.order('id').page 1 }
|
74
|
-
its('order_values.uniq') { should == ['id'] }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe '#per' do
|
79
|
-
context 'page 1 per 5' do
|
80
|
-
subject { model_class.page(1).per(5) }
|
81
|
-
it { should have(5).users }
|
82
|
-
its('first.name') { should == 'user001' }
|
83
|
-
end
|
84
|
-
|
85
|
-
context "page 1 per nil (using default)" do
|
86
|
-
subject { model_class.page(1).per(nil) }
|
87
|
-
it { should have(model_class.default_per_page).users }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#padding' do
|
92
|
-
context 'page 1 per 5 padding 1' do
|
93
|
-
subject { model_class.page(1).per(5).padding(1) }
|
94
|
-
it { should have(5).users }
|
95
|
-
its('first.name') { should == 'user002' }
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'page 19 per 5 padding 5' do
|
99
|
-
subject { model_class.page(19).per(5).padding(5) }
|
100
|
-
its(:current_page) { should == 19 }
|
101
|
-
its(:total_pages) { should == 19 }
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe '#total_pages' do
|
106
|
-
context 'per 25 (default)' do
|
107
|
-
subject { model_class.page }
|
108
|
-
its(:total_pages) { should == 4 }
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'per 7' do
|
112
|
-
subject { model_class.page(2).per(7) }
|
113
|
-
its(:total_pages) { should == 15 }
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'per 65536' do
|
117
|
-
subject { model_class.page(50).per(65536) }
|
118
|
-
its(:total_pages) { should == 1 }
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'per 0 (using default)' do
|
122
|
-
subject { model_class.page(50).per(0) }
|
123
|
-
its(:total_pages) { should == 4 }
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'per -1 (using default)' do
|
127
|
-
subject { model_class.page(5).per(-1) }
|
128
|
-
its(:total_pages) { should == 4 }
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'per "String value that can not be converted into Number" (using default)' do
|
132
|
-
subject { model_class.page(5).per('aho') }
|
133
|
-
its(:total_pages) { should == 4 }
|
134
|
-
end
|
135
|
-
|
136
|
-
context 'with max_pages < total pages count from database' do
|
137
|
-
before { model_class.max_pages_per 3 }
|
138
|
-
subject { model_class.page }
|
139
|
-
its(:total_pages) { should == 3 }
|
140
|
-
after { model_class.max_pages_per nil }
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'with max_pages > total pages count from database' do
|
144
|
-
before { model_class.max_pages_per 11 }
|
145
|
-
subject { model_class.page }
|
146
|
-
its(:total_pages) { should == 4 }
|
147
|
-
after { model_class.max_pages_per nil }
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'with max_pages is nil' do
|
151
|
-
before { model_class.max_pages_per nil }
|
152
|
-
subject { model_class.page }
|
153
|
-
its(:total_pages) { should == 4 }
|
154
|
-
end
|
155
|
-
|
156
|
-
context "with per(nil) using default" do
|
157
|
-
subject { model_class.page.per(nil) }
|
158
|
-
its(:total_pages) { should == 4 }
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe '#current_page' do
|
163
|
-
context 'page 1' do
|
164
|
-
subject { model_class.page }
|
165
|
-
its(:current_page) { should == 1 }
|
166
|
-
end
|
167
|
-
|
168
|
-
context 'page 2' do
|
169
|
-
subject { model_class.page(2).per 3 }
|
170
|
-
its(:current_page) { should == 2 }
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe '#next_page' do
|
175
|
-
context 'page 1' do
|
176
|
-
subject { model_class.page }
|
177
|
-
its(:next_page) { should == 2 }
|
178
|
-
end
|
179
|
-
|
180
|
-
context 'page 5' do
|
181
|
-
subject { model_class.page(5) }
|
182
|
-
its(:next_page) { should be_nil }
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
describe '#prev_page' do
|
187
|
-
context 'page 1' do
|
188
|
-
subject { model_class.page }
|
189
|
-
its(:prev_page) { should be_nil }
|
190
|
-
end
|
191
|
-
|
192
|
-
context 'page 5' do
|
193
|
-
subject { model_class.page(5) }
|
194
|
-
its(:prev_page) { should == 4 }
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
describe '#first_page?' do
|
199
|
-
context 'on first page' do
|
200
|
-
subject { model_class.page(1).per(10) }
|
201
|
-
its(:first_page?) { should == true }
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'not on first page' do
|
205
|
-
subject { model_class.page(5).per(10) }
|
206
|
-
its(:first_page?) { should == false }
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
describe '#last_page?' do
|
211
|
-
context 'on last page' do
|
212
|
-
subject { model_class.page(10).per(10) }
|
213
|
-
its(:last_page?) { should == true }
|
214
|
-
end
|
215
|
-
|
216
|
-
context 'not on last page' do
|
217
|
-
subject { model_class.page(1).per(10) }
|
218
|
-
its(:last_page?) { should == false }
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe '#out_of_range?' do
|
223
|
-
context 'on last page' do
|
224
|
-
subject { model_class.page(10).per(10) }
|
225
|
-
its(:out_of_range?) { should == false }
|
226
|
-
end
|
227
|
-
|
228
|
-
context 'within range' do
|
229
|
-
subject { model_class.page(1).per(10) }
|
230
|
-
its(:out_of_range?) { should == false }
|
231
|
-
end
|
232
|
-
|
233
|
-
context 'out of range' do
|
234
|
-
subject { model_class.page(11).per(10) }
|
235
|
-
its(:out_of_range?) { should == true }
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
describe '#count' do
|
240
|
-
context 'page 1' do
|
241
|
-
subject { model_class.page }
|
242
|
-
its(:count) { should == 25 }
|
243
|
-
end
|
244
|
-
|
245
|
-
context 'page 2' do
|
246
|
-
subject { model_class.page 2 }
|
247
|
-
its(:count) { should == 25 }
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
context 'chained with .group' do
|
252
|
-
subject { model_class.group('age').page(2).per 5 }
|
253
|
-
# 0..10
|
254
|
-
its(:total_count) { should == 11 }
|
255
|
-
its(:total_pages) { should == 3 }
|
256
|
-
end
|
257
|
-
|
258
|
-
context 'activerecord descendants' do
|
259
|
-
subject { ActiveRecord::Base.descendants }
|
260
|
-
its(:length) { should_not == 0 }
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
data/spec/models/array_spec.rb
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Kaminari::PaginatableArray do
|
4
|
-
it { should have(0).items }
|
5
|
-
|
6
|
-
context 'specifying limit and offset when initializing' do
|
7
|
-
subject { Kaminari::PaginatableArray.new((1..100).to_a, :limit => 10, :offset => 20) }
|
8
|
-
its(:current_page) { should == 3 }
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:array) { Kaminari::PaginatableArray.new((1..100).to_a) }
|
12
|
-
describe '#page' do
|
13
|
-
shared_examples_for 'the first page of array' do
|
14
|
-
it { should have(25).users }
|
15
|
-
its(:current_page) { should == 1 }
|
16
|
-
its(:first) { should == 1 }
|
17
|
-
end
|
18
|
-
|
19
|
-
shared_examples_for 'blank array page' do
|
20
|
-
it { should have(0).items }
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'page 1' do
|
24
|
-
subject { array.page 1 }
|
25
|
-
it_should_behave_like 'the first page of array'
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'page 2' do
|
29
|
-
subject { array.page 2 }
|
30
|
-
it { should have(25).users }
|
31
|
-
its(:current_page) { should == 2 }
|
32
|
-
its(:first) { should == 26 }
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'page without an argument' do
|
36
|
-
subject { array.page }
|
37
|
-
it_should_behave_like 'the first page of array'
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'page < 1' do
|
41
|
-
subject { array.page 0 }
|
42
|
-
it_should_behave_like 'the first page of array'
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'page > max page' do
|
46
|
-
subject { array.page 5 }
|
47
|
-
it_should_behave_like 'blank array page'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#per' do
|
52
|
-
context 'page 1 per 5' do
|
53
|
-
subject { array.page(1).per(5) }
|
54
|
-
it { should have(5).users }
|
55
|
-
its(:first) { should == 1 }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#total_pages' do
|
60
|
-
context 'per 25 (default)' do
|
61
|
-
subject { array.page }
|
62
|
-
its(:total_pages) { should == 4 }
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'per 7' do
|
66
|
-
subject { array.page(2).per(7) }
|
67
|
-
its(:total_pages) { should == 15 }
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'per 65536' do
|
71
|
-
subject { array.page(50).per(65536) }
|
72
|
-
its(:total_pages) { should == 1 }
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'per 0 (using default)' do
|
76
|
-
subject { array.page(50).per(0) }
|
77
|
-
its(:total_pages) { should == 4 }
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'per -1 (using default)' do
|
81
|
-
subject { array.page(5).per(-1) }
|
82
|
-
its(:total_pages) { should == 4 }
|
83
|
-
end
|
84
|
-
|
85
|
-
context 'per "String value that can not be converted into Number" (using default)' do
|
86
|
-
subject { array.page(5).per('aho') }
|
87
|
-
its(:total_pages) { should == 4 }
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'per 25, padding 25' do
|
91
|
-
subject { array.page(1).padding(25) }
|
92
|
-
its(:total_pages) { should == 3 }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe '#current_page' do
|
97
|
-
context 'page 1' do
|
98
|
-
subject { array.page }
|
99
|
-
its(:current_page) { should == 1 }
|
100
|
-
end
|
101
|
-
|
102
|
-
context 'page 2' do
|
103
|
-
subject { array.page(2).per 3 }
|
104
|
-
its(:current_page) { should == 2 }
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe '#next_page' do
|
109
|
-
context 'page 1' do
|
110
|
-
subject { array.page }
|
111
|
-
its(:next_page) { should == 2 }
|
112
|
-
end
|
113
|
-
|
114
|
-
context 'page 5' do
|
115
|
-
subject { array.page 5 }
|
116
|
-
its(:next_page) { should be_nil }
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe '#prev_page' do
|
121
|
-
context 'page 1' do
|
122
|
-
subject { array.page }
|
123
|
-
its(:prev_page) { should be_nil }
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'page 5' do
|
127
|
-
subject { array.page 5 }
|
128
|
-
its(:prev_page) { should == 4 }
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe '#count' do
|
133
|
-
context 'page 1' do
|
134
|
-
subject { array.page }
|
135
|
-
its(:count) { should == 25 }
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'page 2' do
|
139
|
-
subject { array.page 2 }
|
140
|
-
its(:count) { should == 25 }
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context 'when setting total count explicitly' do
|
145
|
-
context "array 1..10, page 5, per 10, total_count 9999" do
|
146
|
-
subject { Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10) }
|
147
|
-
|
148
|
-
it { should have(10).items }
|
149
|
-
its(:first) { should == 1 }
|
150
|
-
its(:current_page) { should == 5 }
|
151
|
-
its(:total_count) { should == 9999 }
|
152
|
-
end
|
153
|
-
|
154
|
-
context "array 1..15, page 1, per 10, total_count 15" do
|
155
|
-
subject { Kaminari.paginate_array((1..15).to_a, :total_count => 15).page(1).per(10) }
|
156
|
-
|
157
|
-
it { should have(10).items }
|
158
|
-
its(:first) { should == 1 }
|
159
|
-
its(:current_page) { should == 1 }
|
160
|
-
its(:total_count) { should == 15 }
|
161
|
-
end
|
162
|
-
|
163
|
-
context "array 1..25, page 2, per 10, total_count 15" do
|
164
|
-
subject { Kaminari.paginate_array((1..25).to_a, :total_count => 15).page(2).per(10) }
|
165
|
-
|
166
|
-
it { should have(5).items }
|
167
|
-
its(:first) { should == 11 }
|
168
|
-
its(:current_page) { should == 2 }
|
169
|
-
its(:total_count) { should == 15 }
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|