kaminari 0.15.1 → 0.16.0

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.

Files changed (46) hide show
  1. data/.travis.yml +17 -4
  2. data/CHANGELOG.rdoc +25 -0
  3. data/README.rdoc +23 -6
  4. data/Rakefile +2 -2
  5. data/gemfiles/active_record_30.gemfile +7 -3
  6. data/gemfiles/active_record_31.gemfile +7 -3
  7. data/gemfiles/active_record_32.gemfile +7 -3
  8. data/gemfiles/active_record_40.gemfile +9 -5
  9. data/gemfiles/active_record_41.gemfile +24 -0
  10. data/gemfiles/active_record_edge.gemfile +7 -3
  11. data/gemfiles/data_mapper_12.gemfile +7 -3
  12. data/gemfiles/mongo_mapper.gemfile +7 -2
  13. data/gemfiles/mongoid_24.gemfile +2 -2
  14. data/gemfiles/mongoid_30.gemfile +2 -1
  15. data/gemfiles/mongoid_31.gemfile +1 -1
  16. data/gemfiles/mongoid_40.gemfile +14 -0
  17. data/gemfiles/sinatra_13.gemfile +7 -4
  18. data/gemfiles/sinatra_14.gemfile +14 -6
  19. data/lib/generators/kaminari/views_generator.rb +3 -3
  20. data/lib/kaminari/helpers/action_view_extension.rb +5 -25
  21. data/lib/kaminari/helpers/paginator.rb +10 -3
  22. data/lib/kaminari/helpers/sinatra_helpers.rb +33 -2
  23. data/lib/kaminari/helpers/tags.rb +12 -2
  24. data/lib/kaminari/hooks.rb +0 -1
  25. data/lib/kaminari/models/active_record_extension.rb +2 -2
  26. data/lib/kaminari/models/active_record_relation_methods.rb +4 -0
  27. data/lib/kaminari/models/array_extension.rb +8 -4
  28. data/lib/kaminari/models/data_mapper_collection_methods.rb +4 -0
  29. data/lib/kaminari/models/mongoid_criteria_methods.rb +13 -1
  30. data/lib/kaminari/models/mongoid_extension.rb +0 -12
  31. data/lib/kaminari/models/plucky_criteria_methods.rb +4 -0
  32. data/lib/kaminari/version.rb +1 -1
  33. data/spec/fake_app/active_record/config.rb +1 -1
  34. data/spec/fake_app/mongoid/config.rb +3 -1
  35. data/spec/fake_app/mongoid/models.rb +4 -0
  36. data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +1 -0
  37. data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +3 -0
  38. data/spec/generators/views_generator_spec.rb +18 -0
  39. data/spec/helpers/action_view_extension_spec.rb +17 -10
  40. data/spec/helpers/helpers_spec.rb +9 -0
  41. data/spec/helpers/sinatra_helpers_spec.rb +53 -0
  42. data/spec/models/array_spec.rb +23 -4
  43. data/spec/models/mongoid/mongoid_spec.rb +72 -1
  44. data/spec/spec_helper.rb +1 -0
  45. metadata +62 -32
  46. checksums.yaml +0 -7
@@ -8,10 +8,19 @@ describe 'Kaminari::Helpers::Paginator' do
8
8
  params { {} }
9
9
  options { {} }
10
10
  url_for {|h| "/foo?page=#{h[:page]}"}
11
+ link_to { "<a href='#'>link</a>" }
11
12
  end
12
13
  r
13
14
  end
14
15
 
16
+ describe "view helper methods delegated to template" do
17
+ before do
18
+ @paginator = Paginator.new(template, :params => {})
19
+ end
20
+ subject { @paginator.link_to("link", "#") }
21
+ it { should == "<a href='#'>link</a>" }
22
+ end
23
+
15
24
  describe '#params' do
16
25
  before do
17
26
  @paginator = Paginator.new(template, :params => {:controller => 'foo', :action => 'bar'})
@@ -12,6 +12,17 @@ if defined? Sinatra
12
12
  </div>
13
13
  EOT
14
14
 
15
+ ERB_TEMPLATE_FOR_PREVIOUS_PAGE = <<EOT
16
+ <div>
17
+ <ul>
18
+ <% @users.each do |user| %>
19
+ <li class="user_info"><%= user.id %></li>
20
+ <% end %>
21
+ </ul>
22
+ <%= link_to_previous_page(@users, "Previous!", {:id => 'previous_page_link'}.merge(@options || {})) %>
23
+ </div>
24
+ EOT
25
+
15
26
  ERB_TEMPLATE_FOR_NEXT_PAGE = <<EOT
16
27
  <div>
17
28
  <ul>
@@ -125,6 +136,48 @@ EOT
125
136
  end
126
137
  end
127
138
 
139
+ describe '#link_to_previous_page' do
140
+ before do
141
+ mock_app do
142
+ register Kaminari::Helpers::SinatraHelpers
143
+ get '/users' do
144
+ @page = params[:page] || 2
145
+ @users = User.page(@page)
146
+ erb ERB_TEMPLATE_FOR_PREVIOUS_PAGE
147
+ end
148
+
149
+ get '/users_placeholder' do
150
+ @page = params[:page] || 2
151
+ @options = {:placeholder => %{<span id='no_previous_page'>No Previous Page</span>}}
152
+ @users = User.page(@page)
153
+ erb ERB_TEMPLATE_FOR_PREVIOUS_PAGE
154
+ end
155
+ end
156
+ end
157
+
158
+ context 'having more page' do
159
+ it 'should have a more page link' do
160
+ get '/users'
161
+ last_document.search('a#previous_page_link').should be_present
162
+ last_document.search('a#previous_page_link').text.should match(/Previous!/)
163
+ end
164
+ end
165
+
166
+ context 'the first page' do
167
+ it 'should not have a more page link' do
168
+ get '/users?page=1'
169
+ last_document.search('a#previous_page_link').should be_empty
170
+ end
171
+
172
+ it 'should have a no more page notation using placeholder' do
173
+ get '/users_placeholder?page=1'
174
+ last_document.search('a#previous_page_link').should be_empty
175
+ last_document.search('span#no_previous_page').should be_present
176
+ last_document.search('span#no_previous_page').text.should match(/No Previous Page/)
177
+ end
178
+ end
179
+ end
180
+
128
181
  describe '#link_to_next_page' do
129
182
  before do
130
183
  mock_app do
@@ -142,9 +142,28 @@ describe Kaminari::PaginatableArray do
142
142
  end
143
143
 
144
144
  context 'when setting total count explicitly' do
145
- subject { Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10) }
146
- it { should have(10).items }
147
- its(:first) { should == 1 }
148
- its(:total_count) { should == 9999 }
145
+ context "total_count > size of the given array" do
146
+ subject { Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10) }
147
+
148
+ it { should have(0).items }
149
+ its(:first) { should be_nil }
150
+ its(:total_count) { should == 9999 }
151
+ end
152
+
153
+ context "total_count == size of the given array" do
154
+ subject { Kaminari.paginate_array((1..15).to_a, :total_count => 15).page(1).per(10) }
155
+
156
+ it { should have(10).items }
157
+ its(:first) { should == 1 }
158
+ its(:total_count) { should == 15 }
159
+ end
160
+
161
+ context "total_count < size of the given array" do
162
+ subject { Kaminari.paginate_array((1..25).to_a, :total_count => 15).page(2).per(10) }
163
+
164
+ it { should have(5).items }
165
+ its(:first) { should == 11 }
166
+ its(:total_count) { should == 15 }
167
+ end
149
168
  end
150
169
  end
@@ -8,6 +8,60 @@ if defined? Mongoid
8
8
  end
9
9
  end
10
10
 
11
+ describe 'max_scan', :if => Mongoid::VERSION >= '3' do
12
+ context 'less than total' do
13
+ context 'page 1' do
14
+ subject { User.max_scan(20).page 1 }
15
+ it { should be_a Mongoid::Criteria }
16
+ its(:current_page) { should == 1 }
17
+ its(:prev_page) { should be_nil }
18
+ its(:next_page) { should be_nil }
19
+ its(:limit_value) { should == 25 }
20
+ its(:total_pages) { should == 1 }
21
+ its(:total_count) { should == 20 }
22
+ it { should skip(0) }
23
+ end
24
+
25
+ context 'page 2' do
26
+ subject { User.max_scan(30).page 2 }
27
+ it { should be_a Mongoid::Criteria }
28
+ its(:current_page) { should == 2 }
29
+ its(:prev_page) { should == 1 }
30
+ its(:next_page) { should be_nil }
31
+ its(:limit_value) { should == 25 }
32
+ its(:total_pages) { should == 2 }
33
+ its(:total_count) { should == 30 }
34
+ it { should skip 25 }
35
+ end
36
+ end
37
+
38
+ context 'more than total' do
39
+ context 'page 1' do
40
+ subject { User.max_scan(60).page 1 }
41
+ it { should be_a Mongoid::Criteria }
42
+ its(:current_page) { should == 1 }
43
+ its(:prev_page) { should be_nil }
44
+ its(:next_page) { should == 2 }
45
+ its(:limit_value) { should == 25 }
46
+ its(:total_pages) { should == 2 }
47
+ its(:total_count) { should == 41 }
48
+ it { should skip(0) }
49
+ end
50
+
51
+ context 'page 2' do
52
+ subject { User.max_scan(60).page 2 }
53
+ it { should be_a Mongoid::Criteria }
54
+ its(:current_page) { should == 2 }
55
+ its(:prev_page) { should == 1 }
56
+ its(:next_page) { should be_nil }
57
+ its(:limit_value) { should == 25 }
58
+ its(:total_pages) { should == 2 }
59
+ its(:total_count) { should == 41 }
60
+ it { should skip 25 }
61
+ end
62
+ end
63
+ end
64
+
11
65
  describe '#page' do
12
66
 
13
67
  context 'page 1' do
@@ -44,7 +98,7 @@ if defined? Mongoid
44
98
  end
45
99
 
46
100
  shared_examples 'complete valid pagination' do
47
- if Mongoid::VERSION =~ /^3/
101
+ if Mongoid::VERSION > '3.0.0'
48
102
  its(:selector) { should == {'salary' => 1} }
49
103
  else
50
104
  its(:selector) { should == {:salary => 1} }
@@ -66,6 +120,23 @@ if defined? Mongoid
66
120
  subject { User.page(2).where(:salary => 1) }
67
121
  it_should_behave_like 'complete valid pagination'
68
122
  end
123
+
124
+ context "with database:", :if => Mongoid::VERSION >= '3' do
125
+ before :all do
126
+ 15.times { User.with(:database => "default_db").create!(:salary => 1) }
127
+ 10.times { User.with(:database => "other_db").create!(:salary => 1) }
128
+ end
129
+
130
+ context "default_db" do
131
+ subject { User.with(:database => "default_db").order_by(:artist.asc).page(1) }
132
+ its(:total_count) { should == 15 }
133
+ end
134
+
135
+ context "other_db" do
136
+ subject { User.with(:database => "other_db").order_by(:artist.asc).page(1) }
137
+ its(:total_count) { should == 10 }
138
+ end
139
+ end
69
140
  end
70
141
 
71
142
  describe '#per' do
data/spec/spec_helper.rb CHANGED
@@ -30,4 +30,5 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
30
30
 
31
31
  RSpec.configure do |config|
32
32
  config.mock_with :rr
33
+ config.filter_run_excluding :generator_spec => true if !ENV['GENERATOR_SPEC']
33
34
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaminari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.16.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Akira Matsuda
@@ -11,146 +12,166 @@ authors:
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2014-01-15 00:00:00.000000000 Z
15
+ date: 2014-06-08 00:00:00.000000000 Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: activesupport
18
19
  requirement: !ruby/object:Gem::Requirement
20
+ none: false
19
21
  requirements:
20
- - - ">="
22
+ - - ! '>='
21
23
  - !ruby/object:Gem::Version
22
24
  version: 3.0.0
23
25
  type: :runtime
24
26
  prerelease: false
25
27
  version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
26
29
  requirements:
27
- - - ">="
30
+ - - ! '>='
28
31
  - !ruby/object:Gem::Version
29
32
  version: 3.0.0
30
33
  - !ruby/object:Gem::Dependency
31
34
  name: actionpack
32
35
  requirement: !ruby/object:Gem::Requirement
36
+ none: false
33
37
  requirements:
34
- - - ">="
38
+ - - ! '>='
35
39
  - !ruby/object:Gem::Version
36
40
  version: 3.0.0
37
41
  type: :runtime
38
42
  prerelease: false
39
43
  version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
40
45
  requirements:
41
- - - ">="
46
+ - - ! '>='
42
47
  - !ruby/object:Gem::Version
43
48
  version: 3.0.0
44
49
  - !ruby/object:Gem::Dependency
45
50
  name: bundler
46
51
  requirement: !ruby/object:Gem::Requirement
52
+ none: false
47
53
  requirements:
48
- - - ">="
54
+ - - ! '>='
49
55
  - !ruby/object:Gem::Version
50
56
  version: 1.0.0
51
57
  type: :development
52
58
  prerelease: false
53
59
  version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
54
61
  requirements:
55
- - - ">="
62
+ - - ! '>='
56
63
  - !ruby/object:Gem::Version
57
64
  version: 1.0.0
58
65
  - !ruby/object:Gem::Dependency
59
66
  name: rake
60
67
  requirement: !ruby/object:Gem::Requirement
68
+ none: false
61
69
  requirements:
62
- - - ">="
70
+ - - ! '>='
63
71
  - !ruby/object:Gem::Version
64
72
  version: '0'
65
73
  type: :development
66
74
  prerelease: false
67
75
  version_requirements: !ruby/object:Gem::Requirement
76
+ none: false
68
77
  requirements:
69
- - - ">="
78
+ - - ! '>='
70
79
  - !ruby/object:Gem::Version
71
80
  version: '0'
72
81
  - !ruby/object:Gem::Dependency
73
82
  name: tzinfo
74
83
  requirement: !ruby/object:Gem::Requirement
84
+ none: false
75
85
  requirements:
76
- - - ">="
86
+ - - ! '>='
77
87
  - !ruby/object:Gem::Version
78
88
  version: '0'
79
89
  type: :development
80
90
  prerelease: false
81
91
  version_requirements: !ruby/object:Gem::Requirement
92
+ none: false
82
93
  requirements:
83
- - - ">="
94
+ - - ! '>='
84
95
  - !ruby/object:Gem::Version
85
96
  version: '0'
86
97
  - !ruby/object:Gem::Dependency
87
98
  name: rspec
88
99
  requirement: !ruby/object:Gem::Requirement
100
+ none: false
89
101
  requirements:
90
- - - ">="
102
+ - - ! '>='
91
103
  - !ruby/object:Gem::Version
92
104
  version: '0'
93
105
  type: :development
94
106
  prerelease: false
95
107
  version_requirements: !ruby/object:Gem::Requirement
108
+ none: false
96
109
  requirements:
97
- - - ">="
110
+ - - ! '>='
98
111
  - !ruby/object:Gem::Version
99
112
  version: '0'
100
113
  - !ruby/object:Gem::Dependency
101
114
  name: rr
102
115
  requirement: !ruby/object:Gem::Requirement
116
+ none: false
103
117
  requirements:
104
- - - ">="
118
+ - - ! '>='
105
119
  - !ruby/object:Gem::Version
106
120
  version: '0'
107
121
  type: :development
108
122
  prerelease: false
109
123
  version_requirements: !ruby/object:Gem::Requirement
124
+ none: false
110
125
  requirements:
111
- - - ">="
126
+ - - ! '>='
112
127
  - !ruby/object:Gem::Version
113
128
  version: '0'
114
129
  - !ruby/object:Gem::Dependency
115
130
  name: capybara
116
131
  requirement: !ruby/object:Gem::Requirement
132
+ none: false
117
133
  requirements:
118
- - - ">="
134
+ - - ! '>='
119
135
  - !ruby/object:Gem::Version
120
136
  version: '1.0'
121
137
  type: :development
122
138
  prerelease: false
123
139
  version_requirements: !ruby/object:Gem::Requirement
140
+ none: false
124
141
  requirements:
125
- - - ">="
142
+ - - ! '>='
126
143
  - !ruby/object:Gem::Version
127
144
  version: '1.0'
128
145
  - !ruby/object:Gem::Dependency
129
146
  name: database_cleaner
130
147
  requirement: !ruby/object:Gem::Requirement
148
+ none: false
131
149
  requirements:
132
- - - "~>"
150
+ - - ~>
133
151
  - !ruby/object:Gem::Version
134
152
  version: 1.2.0
135
153
  type: :development
136
154
  prerelease: false
137
155
  version_requirements: !ruby/object:Gem::Requirement
156
+ none: false
138
157
  requirements:
139
- - - "~>"
158
+ - - ~>
140
159
  - !ruby/object:Gem::Version
141
160
  version: 1.2.0
142
161
  - !ruby/object:Gem::Dependency
143
162
  name: rdoc
144
163
  requirement: !ruby/object:Gem::Requirement
164
+ none: false
145
165
  requirements:
146
- - - ">="
166
+ - - ! '>='
147
167
  - !ruby/object:Gem::Version
148
168
  version: '0'
149
169
  type: :development
150
170
  prerelease: false
151
171
  version_requirements: !ruby/object:Gem::Requirement
172
+ none: false
152
173
  requirements:
153
- - - ">="
174
+ - - ! '>='
154
175
  - !ruby/object:Gem::Version
155
176
  version: '0'
156
177
  description: Kaminari is a Scope & Engine based, clean, powerful, agnostic, customizable
@@ -162,11 +183,11 @@ extensions: []
162
183
  extra_rdoc_files:
163
184
  - README.rdoc
164
185
  files:
165
- - ".document"
166
- - ".gemtest"
167
- - ".gitignore"
168
- - ".rspec"
169
- - ".travis.yml"
186
+ - .document
187
+ - .gemtest
188
+ - .gitignore
189
+ - .rspec
190
+ - .travis.yml
170
191
  - CHANGELOG.rdoc
171
192
  - Gemfile
172
193
  - MIT-LICENSE
@@ -198,12 +219,14 @@ files:
198
219
  - gemfiles/active_record_31.gemfile
199
220
  - gemfiles/active_record_32.gemfile
200
221
  - gemfiles/active_record_40.gemfile
222
+ - gemfiles/active_record_41.gemfile
201
223
  - gemfiles/active_record_edge.gemfile
202
224
  - gemfiles/data_mapper_12.gemfile
203
225
  - gemfiles/mongo_mapper.gemfile
204
226
  - gemfiles/mongoid_24.gemfile
205
227
  - gemfiles/mongoid_30.gemfile
206
228
  - gemfiles/mongoid_31.gemfile
229
+ - gemfiles/mongoid_40.gemfile
207
230
  - gemfiles/sinatra_13.gemfile
208
231
  - gemfiles/sinatra_14.gemfile
209
232
  - kaminari.gemspec
@@ -245,7 +268,10 @@ files:
245
268
  - spec/fake_app/mongoid/models.rb
246
269
  - spec/fake_app/rails_app.rb
247
270
  - spec/fake_app/sinatra_app.rb
271
+ - spec/fake_app/views/alternative/kaminari/_first_page.html.erb
272
+ - spec/fake_app/views/alternative/kaminari/_paginator.html.erb
248
273
  - spec/fake_gem.rb
274
+ - spec/generators/views_generator_spec.rb
249
275
  - spec/helpers/action_view_extension_spec.rb
250
276
  - spec/helpers/helpers_spec.rb
251
277
  - spec/helpers/sinatra_helpers_spec.rb
@@ -265,26 +291,27 @@ files:
265
291
  homepage: https://github.com/amatsuda/kaminari
266
292
  licenses:
267
293
  - MIT
268
- metadata: {}
269
294
  post_install_message:
270
295
  rdoc_options: []
271
296
  require_paths:
272
297
  - lib
273
298
  required_ruby_version: !ruby/object:Gem::Requirement
299
+ none: false
274
300
  requirements:
275
- - - ">="
301
+ - - ! '>='
276
302
  - !ruby/object:Gem::Version
277
303
  version: '0'
278
304
  required_rubygems_version: !ruby/object:Gem::Requirement
305
+ none: false
279
306
  requirements:
280
- - - ">="
307
+ - - ! '>='
281
308
  - !ruby/object:Gem::Version
282
309
  version: '0'
283
310
  requirements: []
284
311
  rubyforge_project: kaminari
285
- rubygems_version: 2.2.0
312
+ rubygems_version: 1.8.23.2
286
313
  signing_key:
287
- specification_version: 4
314
+ specification_version: 3
288
315
  summary: A pagination engine plugin for Rails 3+ and other modern frameworks
289
316
  test_files:
290
317
  - spec/config/config_spec.rb
@@ -298,7 +325,10 @@ test_files:
298
325
  - spec/fake_app/mongoid/models.rb
299
326
  - spec/fake_app/rails_app.rb
300
327
  - spec/fake_app/sinatra_app.rb
328
+ - spec/fake_app/views/alternative/kaminari/_first_page.html.erb
329
+ - spec/fake_app/views/alternative/kaminari/_paginator.html.erb
301
330
  - spec/fake_gem.rb
331
+ - spec/generators/views_generator_spec.rb
302
332
  - spec/helpers/action_view_extension_spec.rb
303
333
  - spec/helpers/helpers_spec.rb
304
334
  - spec/helpers/sinatra_helpers_spec.rb