kaminari 0.16.3 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +19 -0
  3. data/.gitignore +1 -1
  4. data/.travis.yml +82 -47
  5. data/CHANGELOG.md +636 -0
  6. data/CONTRIBUTING.md +22 -0
  7. data/Gemfile +2 -0
  8. data/README.md +573 -0
  9. data/Rakefile +33 -14
  10. data/gemfiles/active_record_41.gemfile +10 -6
  11. data/gemfiles/active_record_42.gemfile +10 -6
  12. data/gemfiles/active_record_50.gemfile +24 -0
  13. data/gemfiles/active_record_51.gemfile +24 -0
  14. data/gemfiles/active_record_52.gemfile +24 -0
  15. data/gemfiles/active_record_60.gemfile +26 -0
  16. data/gemfiles/active_record_edge.gemfile +15 -12
  17. data/kaminari.gemspec +23 -27
  18. data/lib/kaminari/version.rb +3 -1
  19. data/lib/kaminari.rb +4 -38
  20. data/misc/bug_report_template.rb +57 -0
  21. metadata +48 -186
  22. data/.gemtest +0 -0
  23. data/.rspec +0 -2
  24. data/CHANGELOG.rdoc +0 -453
  25. data/README.rdoc +0 -336
  26. data/app/views/kaminari/_first_page.html.erb +0 -11
  27. data/app/views/kaminari/_first_page.html.haml +0 -9
  28. data/app/views/kaminari/_first_page.html.slim +0 -10
  29. data/app/views/kaminari/_gap.html.erb +0 -8
  30. data/app/views/kaminari/_gap.html.haml +0 -8
  31. data/app/views/kaminari/_gap.html.slim +0 -9
  32. data/app/views/kaminari/_last_page.html.erb +0 -11
  33. data/app/views/kaminari/_last_page.html.haml +0 -9
  34. data/app/views/kaminari/_last_page.html.slim +0 -10
  35. data/app/views/kaminari/_next_page.html.erb +0 -11
  36. data/app/views/kaminari/_next_page.html.haml +0 -9
  37. data/app/views/kaminari/_next_page.html.slim +0 -10
  38. data/app/views/kaminari/_page.html.erb +0 -12
  39. data/app/views/kaminari/_page.html.haml +0 -10
  40. data/app/views/kaminari/_page.html.slim +0 -11
  41. data/app/views/kaminari/_paginator.html.erb +0 -23
  42. data/app/views/kaminari/_paginator.html.haml +0 -18
  43. data/app/views/kaminari/_paginator.html.slim +0 -19
  44. data/app/views/kaminari/_prev_page.html.erb +0 -11
  45. data/app/views/kaminari/_prev_page.html.haml +0 -9
  46. data/app/views/kaminari/_prev_page.html.slim +0 -10
  47. data/config/locales/kaminari.yml +0 -19
  48. data/gemfiles/active_record_30.gemfile +0 -30
  49. data/gemfiles/active_record_31.gemfile +0 -33
  50. data/gemfiles/active_record_32.gemfile +0 -33
  51. data/gemfiles/active_record_40.gemfile +0 -25
  52. data/gemfiles/data_mapper_12.gemfile +0 -39
  53. data/gemfiles/mongo_mapper.gemfile +0 -31
  54. data/gemfiles/mongoid_24.gemfile +0 -25
  55. data/gemfiles/mongoid_30.gemfile +0 -21
  56. data/gemfiles/mongoid_31.gemfile +0 -20
  57. data/gemfiles/mongoid_40.gemfile +0 -18
  58. data/gemfiles/sinatra_13.gemfile +0 -43
  59. data/gemfiles/sinatra_14.gemfile +0 -43
  60. data/lib/generators/kaminari/config_generator.rb +0 -16
  61. data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
  62. data/lib/generators/kaminari/views_generator.rb +0 -119
  63. data/lib/kaminari/config.rb +0 -51
  64. data/lib/kaminari/engine.rb +0 -4
  65. data/lib/kaminari/grape.rb +0 -4
  66. data/lib/kaminari/helpers/action_view_extension.rb +0 -132
  67. data/lib/kaminari/helpers/paginator.rb +0 -195
  68. data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
  69. data/lib/kaminari/helpers/tags.rb +0 -105
  70. data/lib/kaminari/hooks.rb +0 -36
  71. data/lib/kaminari/models/active_record_extension.rb +0 -22
  72. data/lib/kaminari/models/active_record_model_extension.rb +0 -22
  73. data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
  74. data/lib/kaminari/models/array_extension.rb +0 -66
  75. data/lib/kaminari/models/configuration_methods.rb +0 -48
  76. data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
  77. data/lib/kaminari/models/data_mapper_extension.rb +0 -51
  78. data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
  79. data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
  80. data/lib/kaminari/models/mongoid_extension.rb +0 -26
  81. data/lib/kaminari/models/page_scope_methods.rb +0 -70
  82. data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
  83. data/lib/kaminari/railtie.rb +0 -7
  84. data/lib/kaminari/sinatra.rb +0 -5
  85. data/spec/config/config_spec.rb +0 -91
  86. data/spec/fake_app/active_record/config.rb +0 -3
  87. data/spec/fake_app/active_record/models.rb +0 -65
  88. data/spec/fake_app/data_mapper/config.rb +0 -1
  89. data/spec/fake_app/data_mapper/models.rb +0 -27
  90. data/spec/fake_app/mongo_mapper/config.rb +0 -2
  91. data/spec/fake_app/mongo_mapper/models.rb +0 -9
  92. data/spec/fake_app/mongoid/config.rb +0 -18
  93. data/spec/fake_app/mongoid/models.rb +0 -38
  94. data/spec/fake_app/rails_app.rb +0 -56
  95. data/spec/fake_app/sinatra_app.rb +0 -22
  96. data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
  97. data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
  98. data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
  99. data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
  100. data/spec/fake_gem.rb +0 -20
  101. data/spec/generators/views_generator_spec.rb +0 -18
  102. data/spec/helpers/action_view_extension_spec.rb +0 -306
  103. data/spec/helpers/helpers_spec.rb +0 -144
  104. data/spec/helpers/sinatra_helpers_spec.rb +0 -223
  105. data/spec/helpers/tags_spec.rb +0 -140
  106. data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
  107. data/spec/models/active_record/inherited_spec.rb +0 -9
  108. data/spec/models/active_record/scopes_spec.rb +0 -265
  109. data/spec/models/array_spec.rb +0 -172
  110. data/spec/models/configuration_methods_spec.rb +0 -125
  111. data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
  112. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
  113. data/spec/models/mongoid/mongoid_spec.rb +0 -228
  114. data/spec/requests/users_spec.rb +0 -53
  115. data/spec/spec_helper.rb +0 -34
  116. data/spec/spec_helper_for_sinatra.rb +0 -34
  117. data/spec/support/database_cleaner.rb +0 -19
  118. data/spec/support/matchers.rb +0 -52
@@ -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
@@ -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
@@ -1,125 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "configuration methods" do
4
- let(:model){ User }
5
-
6
- describe "#default_per_page" do
7
- if defined? ActiveRecord
8
- describe 'AR::Base' do
9
- subject { ActiveRecord::Base }
10
- it { should_not respond_to :paginates_per }
11
- end
12
- end
13
-
14
- subject { model.page(1) }
15
-
16
- context "by default" do
17
- its(:limit_value){ should == 25 }
18
- end
19
-
20
- context "when configuring both on global and model-level" do
21
- before do
22
- Kaminari.configure {|c| c.default_per_page = 50 }
23
- model.paginates_per 100
24
- end
25
-
26
- its(:limit_value){ should == 100 }
27
- end
28
-
29
- context "when configuring multiple times" do
30
- before do
31
- Kaminari.configure {|c| c.default_per_page = 10 }
32
- Kaminari.configure {|c| c.default_per_page = 20 }
33
- end
34
-
35
- its(:limit_value){ should == 20 }
36
- end
37
-
38
- after do
39
- Kaminari.configure {|c| c.default_per_page = 25 }
40
- model.paginates_per nil
41
- end
42
- end
43
-
44
- describe "#max_per_page" do
45
- if defined? ActiveRecord
46
- describe 'AR::Base' do
47
- subject { ActiveRecord::Base }
48
- it { should_not respond_to :max_pages_per }
49
- end
50
- end
51
-
52
- subject { model.page(1).per(1000) }
53
-
54
- context "by default" do
55
- its(:limit_value){ should == 1000 }
56
- end
57
-
58
- context "when configuring both on global and model-level" do
59
- before do
60
- Kaminari.configure {|c| c.max_per_page = 50 }
61
- model.max_paginates_per 100
62
- end
63
-
64
- its(:limit_value){ should == 100 }
65
- end
66
-
67
- context "when configuring multiple times" do
68
- before do
69
- Kaminari.configure {|c| c.max_per_page = 10 }
70
- Kaminari.configure {|c| c.max_per_page = 20 }
71
- end
72
-
73
- its(:limit_value){ should == 20 }
74
- end
75
-
76
- after do
77
- Kaminari.configure {|c| c.max_per_page = nil }
78
- model.max_paginates_per nil
79
- end
80
- end
81
-
82
- describe "#max_pages" do
83
- if defined? ActiveRecord
84
- describe 'AR::Base' do
85
- subject { ActiveRecord::Base }
86
- it { should_not respond_to :max_paginates_per }
87
- end
88
- end
89
-
90
- before do
91
- 100.times do |count|
92
- model.create!(:name => "User#{count}")
93
- end
94
- end
95
-
96
- subject { model.page(1).per(5) }
97
-
98
- context "by default" do
99
- its(:total_pages){ should == 20 }
100
- end
101
-
102
- context "when configuring both on global and model-level" do
103
- before do
104
- Kaminari.configure {|c| c.max_pages = 10 }
105
- model.max_pages_per 15
106
- end
107
-
108
- its(:total_pages){ should == 15 }
109
- end
110
-
111
- context "when configuring multiple times" do
112
- before do
113
- Kaminari.configure {|c| c.max_pages = 10 }
114
- Kaminari.configure {|c| c.max_pages = 15 }
115
- end
116
-
117
- its(:total_pages){ should == 15 }
118
- end
119
-
120
- after do
121
- Kaminari.configure {|c| c.max_pages = nil }
122
- model.max_pages_per nil
123
- end
124
- end
125
- end