kaminari 0.12.4 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kaminari might be problematic. Click here for more details.

Files changed (49) hide show
  1. data/.travis.yml +6 -0
  2. data/CHANGELOG +62 -0
  3. data/{LICENSE.txt → MIT-LICENSE} +0 -0
  4. data/README.rdoc +81 -14
  5. data/kaminari.gemspec +18 -5
  6. data/lib/generators/kaminari/templates/kaminari_config.rb +1 -0
  7. data/lib/generators/kaminari/views_generator.rb +1 -1
  8. data/lib/kaminari.rb +73 -2
  9. data/lib/kaminari/config.rb +3 -1
  10. data/lib/kaminari/helpers/action_view_extension.rb +74 -20
  11. data/lib/kaminari/helpers/paginator.rb +23 -5
  12. data/lib/kaminari/helpers/sinatra_helpers.rb +119 -0
  13. data/lib/kaminari/hooks.rb +35 -0
  14. data/lib/kaminari/models/active_record_extension.rb +12 -15
  15. data/lib/kaminari/models/active_record_model_extension.rb +20 -0
  16. data/lib/kaminari/models/active_record_relation_methods.rb +23 -13
  17. data/lib/kaminari/models/array_extension.rb +33 -15
  18. data/lib/kaminari/models/data_mapper_collection_methods.rb +15 -0
  19. data/lib/kaminari/models/data_mapper_extension.rb +48 -0
  20. data/lib/kaminari/models/mongo_mapper_extension.rb +3 -3
  21. data/lib/kaminari/models/mongoid_criteria_methods.rb +15 -10
  22. data/lib/kaminari/models/mongoid_extension.rb +7 -5
  23. data/lib/kaminari/models/page_scope_methods.rb +27 -26
  24. data/lib/kaminari/models/plucky_criteria_methods.rb +9 -12
  25. data/lib/kaminari/railtie.rb +2 -31
  26. data/lib/kaminari/sinatra.rb +13 -0
  27. data/lib/kaminari/version.rb +1 -1
  28. data/spec/config/config_spec.rb +1 -1
  29. data/spec/fake_app.rb +4 -0
  30. data/spec/fake_gem.rb +6 -0
  31. data/spec/helpers/action_view_extension_spec.rb +105 -10
  32. data/spec/helpers/helpers_spec.rb +1 -1
  33. data/spec/helpers/sinatra_helpers_spec.rb +174 -0
  34. data/spec/helpers/tags_spec.rb +1 -1
  35. data/spec/models/active_record_relation_methods_spec.rb +1 -1
  36. data/spec/models/array_spec.rb +17 -1
  37. data/spec/models/data_mapper_spec.rb +181 -0
  38. data/spec/models/default_per_page_spec.rb +1 -1
  39. data/spec/models/mongo_mapper_spec.rb +14 -11
  40. data/spec/models/mongoid_spec.rb +63 -6
  41. data/spec/models/scopes_spec.rb +154 -140
  42. data/spec/{acceptance → requests}/users_spec.rb +3 -2
  43. data/spec/spec_helper.rb +3 -1
  44. data/spec/spec_helper_for_sinatra.rb +13 -0
  45. data/spec/support/matchers.rb +6 -0
  46. metadata +263 -170
  47. data/spec/acceptance/acceptance_helper.rb +0 -5
  48. data/spec/acceptance/support/helpers.rb +0 -5
  49. data/spec/acceptance/support/paths.rb +0 -9
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
1
+ require 'spec_helper'
2
2
  include Kaminari::Helpers
3
3
 
4
4
  describe 'Kaminari::Helpers' do
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
1
+ require 'spec_helper'
2
2
 
3
3
  describe Kaminari::ActiveRecordRelationMethods do
4
4
  describe '#total_count' do
@@ -1,10 +1,18 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
1
+ require 'spec_helper'
2
2
 
3
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
+
4
11
  let(:array) { Kaminari::PaginatableArray.new((1..100).to_a) }
5
12
  describe '#page' do
6
13
  shared_examples_for 'the first page of array' do
7
14
  it { should have(25).users }
15
+ its(:current_page) { should == 1 }
8
16
  its(:first) { should == 1 }
9
17
  end
10
18
 
@@ -20,6 +28,7 @@ describe Kaminari::PaginatableArray do
20
28
  context 'page 2' do
21
29
  subject { array.page 2 }
22
30
  it { should have(25).users }
31
+ its(:current_page) { should == 2 }
23
32
  its(:first) { should == 26 }
24
33
  end
25
34
 
@@ -102,4 +111,11 @@ describe Kaminari::PaginatableArray do
102
111
  its(:count) { should == 25 }
103
112
  end
104
113
  end
114
+
115
+ context 'when setting total count explicitly' do
116
+ subject { Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10) }
117
+ it { should have(10).items }
118
+ its(:first) { should == 1 }
119
+ its(:total_count) { should == 9999 }
120
+ end
105
121
  end
@@ -0,0 +1,181 @@
1
+ require 'spec_helper'
2
+ require 'dm-core'
3
+ require 'dm-migrations'
4
+ require 'dm-aggregates'
5
+ require 'kaminari/models/data_mapper_extension'
6
+
7
+ describe Kaminari::DataMapperExtension do
8
+ before :all do
9
+ DataMapper.setup(:default, 'sqlite::memory:')
10
+
11
+ class Worker
12
+ include ::DataMapper::Resource
13
+
14
+ property :id, Serial
15
+ property :name, String, :required => true
16
+ property :age, Integer, :required => true
17
+
18
+ has n, :projects, :through => Resource
19
+ end
20
+
21
+ class Project
22
+ include ::DataMapper::Resource
23
+
24
+ property :id, Serial
25
+ property :name, String, :required => true
26
+
27
+ has n, :workers, :through => Resource
28
+ end
29
+
30
+ DataMapper.finalize
31
+ DataMapper.auto_migrate!
32
+
33
+ 300.times do |i|
34
+ Worker.create(:name => "Worker#{i}", :age => i)
35
+ end
36
+
37
+ worker0 = Worker[0]
38
+ 50.times do |i|
39
+ worker0.projects << Project.create(:name => "Project#{i}")
40
+ end
41
+ worker0.projects.save
42
+ end
43
+
44
+ describe 'Collection' do
45
+ subject{ Worker.all }
46
+ it { should respond_to(:page) }
47
+ it { should_not respond_to(:per) }
48
+ end
49
+
50
+ describe 'Model' do
51
+ subject{ Worker }
52
+ it { should respond_to(:page) }
53
+ it { should respond_to(:default_per_page) }
54
+ it { should_not respond_to(:per) }
55
+ end
56
+
57
+ describe '#page' do
58
+ context 'page 0' do
59
+ subject { Worker.all(:age.gte => 200).page 0 }
60
+ it { should be_a DataMapper::Collection }
61
+ its(:current_page) { should == 1 }
62
+ its('query.limit') { should == 25 }
63
+ its('query.offset') { should == 0 }
64
+ its(:total_count) { should == Worker.count(:age.gte => 200) }
65
+ its(:num_pages) { should == 4 }
66
+ end
67
+
68
+ context 'page 1' do
69
+ subject { Worker.all(:age.gte => 0).page 1 }
70
+ it { should be_a DataMapper::Collection }
71
+ its(:current_page) { should == 1 }
72
+ its('query.limit') { should == 25 }
73
+ its('query.offset') { should == 0 }
74
+ its(:total_count) { should == 300 }
75
+ its(:num_pages) { should == 12 }
76
+ end
77
+
78
+ context 'page 2' do
79
+ subject { Worker.page 2 }
80
+ it { should be_a DataMapper::Collection }
81
+ its(:current_page) { should == 2 }
82
+ its(:limit_value) { should == 25 }
83
+ its('query.limit') { should == 25 }
84
+ its('query.offset') { should == 25 }
85
+ its(:total_count) { should == 300 }
86
+ its(:num_pages) { should == 12 }
87
+ end
88
+
89
+ context 'page "foobar"' do
90
+ subject { Worker.page 'foobar' }
91
+ it { should be_a DataMapper::Collection }
92
+ its(:current_page) { should == 1 }
93
+ its('query.limit') { should == 25 }
94
+ its('query.offset') { should == 0 }
95
+ its(:total_count) { should == 300 }
96
+ its(:num_pages) { should == 12 }
97
+ end
98
+
99
+ context 'with criteria before' do
100
+ subject { Worker.all(:age.gt => 100).page 2 }
101
+ it { should be_a DataMapper::Collection }
102
+ its(:current_page) { should == 2 }
103
+ its('query.limit') { should == 25 }
104
+ its('query.offset') { should == 25 }
105
+ its(:total_count) { should == Worker.count(:age.gt => 100) }
106
+ its(:num_pages) { should == 8 }
107
+ end
108
+
109
+ context 'with criteria after' do
110
+ subject { Worker.page(2).all(:age.gt => 100) }
111
+ it { should be_a DataMapper::Collection }
112
+ its(:current_page) { should == 2 }
113
+ its('query.limit') { should == 25 }
114
+ its('query.offset') { should == 25 }
115
+ its(:total_count) { should == Worker.count(:age.gt => 100) }
116
+ its(:num_pages) { should == 8 }
117
+ end
118
+ end
119
+
120
+ describe '#per' do
121
+ context 'on simple query' do
122
+ subject { Worker.page(2).per(10) }
123
+ it { should be_a DataMapper::Collection }
124
+ its(:current_page) { should == 2 }
125
+ its('query.limit') { should == 10 }
126
+ its(:limit_value) { should == 10 }
127
+ its('query.offset') { should == 10 }
128
+ its(:total_count) { should == 300 }
129
+ its(:num_pages) { should == 30 }
130
+ end
131
+
132
+ context 'on query with condition' do
133
+ subject { Worker.page(5).all(:age.lte => 100).per(13) }
134
+ its(:current_page) { should == 5 }
135
+ its('query.limit') { should == 13 }
136
+ its('query.offset') { should == 52 }
137
+ its(:total_count) { should == 101 }
138
+ its(:num_pages) { should == 8 }
139
+ end
140
+
141
+ context 'on query with order' do
142
+ subject { Worker.page(5).all(:age.lte => 100, :order => [:age.asc]).per(13) }
143
+ it('includes worker with age 52') { should include(Worker.first(:age => 52)) }
144
+ it('does not include worker with age 51') { should_not include(Worker.first(:age => 51)) }
145
+ it('includes worker with age 52') { should include(Worker.first(:age => 64)) }
146
+ it('does not include worker with age 51') { should_not include(Worker.first(:age => 65)) }
147
+ its(:current_page) { should == 5 }
148
+ its('query.limit') { should == 13 }
149
+ its('query.offset') { should == 52 }
150
+ its(:total_count) { should == 101 }
151
+ its(:num_pages) { should == 8 }
152
+ end
153
+
154
+ context 'on chained queries' do
155
+ subject { Worker.all(:age.gte => 50).page(3).all(:age.lte => 100).per(13) }
156
+ its(:current_page) { should == 3 }
157
+ its('query.limit') { should == 13 }
158
+ its('query.offset') { should == 26 }
159
+ its(:total_count) { should == 51 }
160
+ its(:num_pages) { should == 4 }
161
+ end
162
+
163
+ context 'on query on association' do
164
+ subject { Worker[0].projects.page(3).all(:name.like => 'Project%').per(5) }
165
+ its(:current_page) { should == 3 }
166
+ its('query.limit') { should == 5 }
167
+ its('query.offset') { should == 10 }
168
+ its(:total_count) { should == 50 }
169
+ its(:num_pages) { should == 10 }
170
+ end
171
+
172
+ context 'on query with association conditions' do
173
+ subject { Worker.page(3).all(:projects => Project.all).per(5) }
174
+ its(:current_page) { should == 3 }
175
+ its('query.limit') { should == 5 }
176
+ its('query.offset') { should == 10 }
177
+ its(:total_count) { should == 50 }
178
+ its(:num_pages) { should == 10 }
179
+ end
180
+ end
181
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
1
+ require 'spec_helper'
2
2
 
3
3
  describe 'default per_page' do
4
4
  describe 'AR::Base' do
@@ -1,18 +1,21 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
1
+ require 'spec_helper'
2
2
  require 'mongo_mapper'
3
- require File.expand_path('../../lib/kaminari/models/mongo_mapper_extension', File.dirname(__FILE__))
3
+ require 'kaminari/models/mongo_mapper_extension'
4
4
 
5
5
  describe Kaminari::MongoMapperExtension do
6
- before :all do
7
- MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
8
- MongoMapper.database = "kaminari_test"
9
- class Developer
10
- include ::MongoMapper::Document
11
- key :salary, Integer
12
- end
13
- end
14
6
  before do
15
- stub(subject).count { 300 } # in order to avoid DB access...
7
+ begin
8
+ MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
9
+ MongoMapper.database = "kaminari_test"
10
+ class Developer
11
+ include ::MongoMapper::Document
12
+ key :salary, Integer
13
+ end
14
+
15
+ stub(subject).count { 300 } # in order to avoid DB access...
16
+ rescue Mongo::ConnectionFailure
17
+ pending 'can not connect to MongoDB'
18
+ end
16
19
  end
17
20
 
18
21
  describe '#page' do
@@ -1,6 +1,6 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
1
+ require 'spec_helper'
2
2
  require 'mongoid'
3
- require File.expand_path('../../lib/kaminari/models/mongoid_extension', File.dirname(__FILE__))
3
+ require 'kaminari/models/mongoid_extension'
4
4
 
5
5
  describe Kaminari::MongoidExtension do
6
6
  before :all do
@@ -9,11 +9,12 @@ describe Kaminari::MongoidExtension do
9
9
  field :salary, :type => Integer
10
10
  end
11
11
  end
12
- before do
13
- stub(subject).count { 300 } # in order to avoid DB access...
14
- end
15
12
 
16
13
  describe '#page' do
14
+ before do
15
+ stub(subject).count { 300 } # in order to avoid DB access...
16
+ end
17
+
17
18
  context 'page 1' do
18
19
  subject { Developer.page 1 }
19
20
  it { should be_a Mongoid::Criteria }
@@ -58,10 +59,13 @@ describe Kaminari::MongoidExtension do
58
59
  its(:num_pages) { should == 12 }
59
60
  it { should skip 25 }
60
61
  end
61
-
62
62
  end
63
63
 
64
64
  describe '#per' do
65
+ before do
66
+ stub(subject).count { 300 } # in order to avoid DB access...
67
+ end
68
+
65
69
  subject { Developer.page(2).per(10) }
66
70
  it { should be_a Mongoid::Criteria }
67
71
  its(:current_page) { should == 2 }
@@ -69,4 +73,57 @@ describe Kaminari::MongoidExtension do
69
73
  its(:num_pages) { should == 30 }
70
74
  it { should skip 10 }
71
75
  end
76
+
77
+ describe '#page in embedded documents' do
78
+ before :all do
79
+ class MongoDeveloper
80
+ include ::Mongoid::Document
81
+ field :salary, :type => Integer
82
+ embeds_many :frameworks
83
+ end
84
+
85
+ class Framework
86
+ include ::Mongoid::Document
87
+ field :name, :type => String
88
+ field :language, :type => String
89
+ embedded_in :mongo_developer
90
+ end
91
+ end
92
+
93
+ before :all do
94
+ @mongo_developer = MongoDeveloper.new
95
+ @mongo_developer.frameworks.new(:name => "rails", :language => "ruby")
96
+ @mongo_developer.frameworks.new(:name => "merb", :language => "ruby")
97
+ @mongo_developer.frameworks.new(:name => "sinatra", :language => "ruby")
98
+ @mongo_developer.frameworks.new(:name => "cakephp", :language => "php")
99
+ @mongo_developer.frameworks.new(:name => "tornado", :language => "python")
100
+ end
101
+
102
+ context 'page 1' do
103
+ subject { @mongo_developer.frameworks.page(1).per(1) }
104
+ it { should be_a Mongoid::Criteria }
105
+ its(:total_count) { should == 5 }
106
+ its(:limit_value) { should == 1 }
107
+ its(:current_page) { should == 1 }
108
+ its(:num_pages) { should == 5 }
109
+ end
110
+
111
+ context 'with criteria after' do
112
+ subject { @mongo_developer.frameworks.page(1).per(2).where(:language => "ruby") }
113
+ it { should be_a Mongoid::Criteria }
114
+ its(:total_count) { should == 3 }
115
+ its(:limit_value) { should == 2 }
116
+ its(:current_page) { should == 1 }
117
+ its(:num_pages) { should == 2 }
118
+ end
119
+
120
+ context 'with criteria before' do
121
+ subject { @mongo_developer.frameworks.where(:language => "ruby").page(1).per(2) }
122
+ it { should be_a Mongoid::Criteria }
123
+ its(:total_count) { should == 3 }
124
+ its(:limit_value) { should == 2 }
125
+ its(:current_page) { should == 1 }
126
+ its(:num_pages) { should == 2 }
127
+ end
128
+ end
72
129
  end
@@ -1,149 +1,163 @@
1
- require File.expand_path('../spec_helper', File.dirname(__FILE__))
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'the first page' do
4
+ it { should have(25).users }
5
+ its('first.name') { should == 'user001' }
6
+ end
7
+
8
+ shared_examples_for 'blank page' do
9
+ it { should have(0).users }
10
+ end
2
11
 
3
12
  describe Kaminari::ActiveRecordExtension do
4
13
  before :all do
5
14
  1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}", :age => (i / 10)}
15
+ 1.upto(100) {|i| GemDefinedModel.create! :name => "user#{'%03d' % i}", :age => (i / 10)}
6
16
  end
7
17
 
8
- describe '#page' do
9
- shared_examples_for 'the first page' do
10
- it { should have(25).users }
11
- its('first.name') { should == 'user001' }
12
- end
13
-
14
- shared_examples_for 'blank page' do
15
- it { should have(0).users }
16
- end
17
-
18
- context 'page 1' do
19
- subject { User.page 1 }
20
- it_should_behave_like 'the first page'
21
- end
22
-
23
- context 'page 2' do
24
- subject { User.page 2 }
25
- it { should have(25).users }
26
- its('first.name') { should == 'user026' }
27
- end
28
-
29
- context 'page without an argument' do
30
- subject { User.page }
31
- it_should_behave_like 'the first page'
32
- end
33
-
34
- context 'page < 1' do
35
- subject { User.page 0 }
36
- it_should_behave_like 'the first page'
37
- end
38
-
39
- context 'page > max page' do
40
- subject { User.page 5 }
41
- it_should_behave_like 'blank page'
42
- end
43
-
44
- describe 'ensure #order_values is preserved' do
45
- subject { User.order('id').page 1 }
46
- its(:order_values) { should == ['id'] }
47
- end
48
- end
49
-
50
- describe '#per' do
51
- context 'page 1 per 5' do
52
- subject { User.page(1).per(5) }
53
- it { should have(5).users }
54
- its('first.name') { should == 'user001' }
55
- end
56
- end
57
-
58
- describe '#num_pages' do
59
- context 'per 25 (default)' do
60
- subject { User.page }
61
- its(:num_pages) { should == 4 }
62
- end
63
-
64
- context 'per 7' do
65
- subject { User.page(2).per(7) }
66
- its(:num_pages) { should == 15 }
67
- end
68
-
69
- context 'per 65536' do
70
- subject { User.page(50).per(65536) }
71
- its(:num_pages) { should == 1 }
72
- end
73
-
74
- context 'per 0 (using default)' do
75
- subject { User.page(50).per(0) }
76
- its(:num_pages) { should == 4 }
77
- end
78
-
79
- context 'per -1 (using default)' do
80
- subject { User.page(5).per(-1) }
81
- its(:num_pages) { should == 4 }
82
- end
83
-
84
- context 'per "String value that can not be converted into Number" (using default)' do
85
- subject { User.page(5).per('aho') }
86
- its(:num_pages) { should == 4 }
87
- end
88
- end
89
-
90
- describe '#current_page' do
91
- context 'page 1' do
92
- subject { User.page }
93
- its(:current_page) { should == 1 }
94
- end
95
-
96
- context 'page 2' do
97
- subject { User.page(2).per 3 }
98
- its(:current_page) { should == 2 }
99
- end
100
- end
101
-
102
- describe '#first_page?' do
103
- context 'on first page' do
104
- subject { User.page(1).per(10) }
105
- its(:first_page?) { should == true }
106
- end
107
-
108
- context 'not on first page' do
109
- subject { User.page(5).per(10) }
110
- its(:first_page?) { should == false }
18
+ [User, Admin, GemDefinedModel].each do |model_class|
19
+ context "for #{model_class}" do
20
+ describe '#page' do
21
+ context 'page 1' do
22
+ subject { model_class.page 1 }
23
+ it_should_behave_like 'the first page'
24
+ end
25
+
26
+ context 'page 2' do
27
+ subject { model_class.page 2 }
28
+ it { should have(25).users }
29
+ its('first.name') { should == 'user026' }
30
+ end
31
+
32
+ context 'page without an argument' do
33
+ subject { model_class.page }
34
+ it_should_behave_like 'the first page'
35
+ end
36
+
37
+ context 'page < 1' do
38
+ subject { model_class.page 0 }
39
+ it_should_behave_like 'the first page'
40
+ end
41
+
42
+ context 'page > max page' do
43
+ subject { model_class.page 5 }
44
+ it_should_behave_like 'blank page'
45
+ end
46
+
47
+ describe 'ensure #order_values is preserved' do
48
+ subject { model_class.order('id').page 1 }
49
+ its('order_values.uniq') { should == ['id'] }
50
+ end
51
+ end
52
+
53
+ describe '#per' do
54
+ context 'page 1 per 5' do
55
+ subject { model_class.page(1).per(5) }
56
+ it { should have(5).users }
57
+ its('first.name') { should == 'user001' }
58
+ end
59
+ end
60
+
61
+ describe '#padding' do
62
+ context 'page 1 per 5 padding 1' do
63
+ subject { model_class.page(1).per(5).padding(1) }
64
+ it { should have(5).users }
65
+ its('first.name') { should == 'user002' }
66
+ end
67
+ end
68
+
69
+ describe '#num_pages' do
70
+ context 'per 25 (default)' do
71
+ subject { model_class.page }
72
+ its(:num_pages) { should == 4 }
73
+ end
74
+
75
+ context 'per 7' do
76
+ subject { model_class.page(2).per(7) }
77
+ its(:num_pages) { should == 15 }
78
+ end
79
+
80
+ context 'per 65536' do
81
+ subject { model_class.page(50).per(65536) }
82
+ its(:num_pages) { should == 1 }
83
+ end
84
+
85
+ context 'per 0 (using default)' do
86
+ subject { model_class.page(50).per(0) }
87
+ its(:num_pages) { should == 4 }
88
+ end
89
+
90
+ context 'per -1 (using default)' do
91
+ subject { model_class.page(5).per(-1) }
92
+ its(:num_pages) { should == 4 }
93
+ end
94
+
95
+ context 'per "String value that can not be converted into Number" (using default)' do
96
+ subject { model_class.page(5).per('aho') }
97
+ its(:num_pages) { should == 4 }
98
+ end
99
+ end
100
+
101
+
102
+ describe '#current_page' do
103
+ context 'page 1' do
104
+ subject { model_class.page }
105
+ its(:current_page) { should == 1 }
106
+ end
107
+
108
+ context 'page 2' do
109
+ subject { model_class.page(2).per 3 }
110
+ its(:current_page) { should == 2 }
111
+ end
112
+ end
113
+
114
+ describe '#first_page?' do
115
+ context 'on first page' do
116
+ subject { model_class.page(1).per(10) }
117
+ its(:first_page?) { should == true }
118
+ end
119
+
120
+ context 'not on first page' do
121
+ subject { model_class.page(5).per(10) }
122
+ its(:first_page?) { should == false }
123
+ end
124
+ end
125
+
126
+ describe '#last_page?' do
127
+ context 'on last page' do
128
+ subject { model_class.page(10).per(10) }
129
+ its(:last_page?) { should == true }
130
+ end
131
+
132
+ context 'not on last page' do
133
+ subject { model_class.page(1).per(10) }
134
+ its(:last_page?) { should == false }
135
+ end
136
+ end
137
+
138
+ describe '#count' do
139
+ context 'page 1' do
140
+ subject { model_class.page }
141
+ its(:count) { should == 25 }
142
+ end
143
+
144
+ context 'page 2' do
145
+ subject { model_class.page 2 }
146
+ its(:count) { should == 25 }
147
+ end
148
+ end
149
+
150
+ context 'chained with .group' do
151
+ subject { model_class.group('age').page(2).per 5 }
152
+ # 0..10
153
+ its(:total_count) { should == 11 }
154
+ its(:num_pages) { should == 3 }
155
+ end
156
+
157
+ context 'activerecord descendants' do
158
+ subject { ActiveRecord::Base.descendants }
159
+ its(:length) { should_not == 0 }
160
+ end
111
161
  end
112
162
  end
113
-
114
- describe '#last_page?' do
115
- context 'on last page' do
116
- subject { User.page(10).per(10) }
117
- its(:last_page?) { should == true }
118
- end
119
-
120
- context 'not on last page' do
121
- subject { User.page(1).per(10) }
122
- its(:last_page?) { should == false }
123
- end
124
- end
125
-
126
- describe '#count' do
127
- context 'page 1' do
128
- subject { User.page }
129
- its(:count) { should == 25 }
130
- end
131
-
132
- context 'page 2' do
133
- subject { User.page 2 }
134
- its(:count) { should == 25 }
135
- end
136
- end
137
-
138
- context 'chained with .group' do
139
- subject { User.group('age').page(2).per 5 }
140
- # 0..10
141
- its(:total_count) { should == 11 }
142
- its(:num_pages) { should == 3 }
143
- end
144
-
145
- context 'activerecord descendants' do
146
- subject { ActiveRecord::Base.descendants }
147
- its(:length) { should_not == 0 }
148
- end
149
163
  end