kaminari 0.16.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) 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 -184
  22. data/.gemtest +0 -0
  23. data/.rspec +0 -2
  24. data/CHANGELOG.rdoc +0 -446
  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 -27
  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 -34
  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 -4
  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/scopes_spec.rb +0 -262
  108. data/spec/models/array_spec.rb +0 -172
  109. data/spec/models/configuration_methods_spec.rb +0 -125
  110. data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
  111. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
  112. data/spec/models/mongoid/mongoid_spec.rb +0 -223
  113. data/spec/requests/users_spec.rb +0 -53
  114. data/spec/spec_helper.rb +0 -34
  115. data/spec/spec_helper_for_sinatra.rb +0 -34
  116. data/spec/support/database_cleaner.rb +0 -19
  117. data/spec/support/matchers.rb +0 -52
@@ -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
@@ -1,205 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if defined? DataMapper
4
- # tests for issue #203
5
- describe Kaminari::DataMapperCollectionMethods do
6
- before do
7
- 30.times do |i|
8
- User.create(:name => "User#{i}", :age => i)
9
- end
10
- end
11
-
12
- describe 'Model' do
13
- subject { User }
14
- it { User.all.count.should == 30 }
15
- it { User.page(1).length.should == 25 }
16
- it {
17
- User.paginates_per(5)
18
- User.page(1).length.should == 5
19
- User.all.page(1).length.should == 5
20
- User.paginates_per(nil) # reset to default
21
- }
22
- end
23
-
24
- end
25
-
26
- describe Kaminari::DataMapperExtension do
27
- before do
28
- 90.times do |i|
29
- User.create(:name => "User#{i}", :age => i)
30
- end
31
- end
32
-
33
- describe 'Collection' do
34
- subject{ User.all }
35
- it { should respond_to(:page) }
36
- it { should_not respond_to(:per) }
37
- end
38
-
39
- describe 'Model' do
40
- subject{ User }
41
- it { should respond_to(:page) }
42
- it { should respond_to(:default_per_page) }
43
- it { should_not respond_to(:per) }
44
- end
45
-
46
- describe '#page' do
47
- context 'page 0' do
48
- subject { User.all(:age.gte => 60).page 0 }
49
- it { should be_a DataMapper::Collection }
50
- its(:current_page) { should == 1 }
51
- its(:prev_page) { should be_nil }
52
- its(:next_page) { should == 2 }
53
- its('query.limit') { should == 25 }
54
- its('query.offset') { should == 0 }
55
- its(:total_count) { should == User.count(:age.gte => 60) }
56
- its(:total_pages) { should == 2 }
57
- end
58
-
59
- context 'page 1' do
60
- subject { User.all(:age.gte => 0).page 1 }
61
- it { should be_a DataMapper::Collection }
62
- its(:current_page) { should == 1 }
63
- its(:prev_page) { should be_nil }
64
- its(:next_page) { should == 2 }
65
- its('query.limit') { should == 25 }
66
- its('query.offset') { should == 0 }
67
- its(:total_count) { should == 90 }
68
- its(:total_pages) { should == 4 }
69
- end
70
-
71
- context 'page 2' do
72
- subject { User.page 2 }
73
- it { should be_a DataMapper::Collection }
74
- its(:current_page) { should == 2 }
75
- its(:prev_page) { should == 1 }
76
- its(:next_page) { should == 3 }
77
- its(:limit_value) { should == 25 }
78
- its('query.limit') { should == 25 }
79
- its('query.offset') { should == 25 }
80
- its(:total_count) { should == 90 }
81
- its(:total_pages) { should == 4 }
82
- end
83
-
84
- context 'page "foobar"' do
85
- subject { User.page 'foobar' }
86
- it { should be_a DataMapper::Collection }
87
- its(:current_page) { should == 1 }
88
- its(:prev_page) { should be_nil }
89
- its(:next_page) { should == 2 }
90
- its('query.limit') { should == 25 }
91
- its('query.offset') { should == 0 }
92
- its(:total_count) { should == 90 }
93
- its(:total_pages) { should == 4 }
94
- end
95
-
96
- context 'with criteria before' do
97
- subject { User.all(:age.gt => 60).page 2 }
98
- it { should be_a DataMapper::Collection }
99
- its(:current_page) { should == 2 }
100
- its(:prev_page) { should == 1 }
101
- its(:next_page) { should be_nil }
102
- its('query.limit') { should == 25 }
103
- its('query.offset') { should == 25 }
104
- its(:total_count) { should == User.count(:age.gt => 60) }
105
- its(:total_pages) { should == 2 }
106
- end
107
-
108
- context 'with criteria after' do
109
- subject { User.page(2).all(:age.gt => 60) }
110
- it { should be_a DataMapper::Collection }
111
- its(:current_page) { should == 2 }
112
- its(:prev_page) { should == 1 }
113
- its(:next_page) { should be_nil }
114
- its('query.limit') { should == 25 }
115
- its('query.offset') { should == 25 }
116
- its(:total_count) { should == User.count(:age.gt => 60) }
117
- its(:total_pages) { should == 2 }
118
- end
119
- end
120
-
121
- describe '#per' do
122
- context 'on simple query' do
123
- subject { User.page(2).per(20) }
124
- it { should be_a DataMapper::Collection }
125
- its(:current_page) { should == 2 }
126
- its(:prev_page) { should == 1 }
127
- its(:next_page) { should == 3 }
128
- its('query.limit') { should == 20 }
129
- its(:limit_value) { should == 20 }
130
- its('query.offset') { should == 20 }
131
- its(:total_count) { should == 90 }
132
- its(:total_pages) { should == 5 }
133
- end
134
-
135
- context 'on query with condition' do
136
- subject { User.page(5).all(:age.lte => 80).per(13) }
137
- its(:current_page) { should == 5 }
138
- its(:prev_page) { should == 4 }
139
- its(:next_page) { should == 6 }
140
- its('query.limit') { should == 13 }
141
- its('query.offset') { should == 52 }
142
- its(:total_count) { should == 81 }
143
- its(:total_pages) { should == 7 }
144
- end
145
-
146
- context 'on query with order' do
147
- subject { User.page(5).all(:age.lte => 80, :order => [:age.asc]).per(13) }
148
- it('includes user with age 52') { should include(User.first(:age => 52)) }
149
- it('does not include user with age 51') { should_not include(User.first(:age => 51)) }
150
- it('includes user with age 52') { should include(User.first(:age => 64)) }
151
- it('does not include user with age 51') { should_not include(User.first(:age => 65)) }
152
- its(:current_page) { should == 5 }
153
- its(:prev_page) { should == 4 }
154
- its(:next_page) { should == 6 }
155
- its('query.limit') { should == 13 }
156
- its('query.offset') { should == 52 }
157
- its(:total_count) { should == 81 }
158
- its(:total_pages) { should == 7 }
159
- end
160
-
161
- context 'on chained queries' do
162
- subject { User.all(:age.gte => 50).page(3).all(:age.lte => 80).per(13) }
163
- its(:current_page) { should == 3 }
164
- its(:prev_page) { should == 2 }
165
- its(:next_page) { should be_nil }
166
- its('query.limit') { should == 13 }
167
- its('query.offset') { should == 26 }
168
- its(:total_count) { should == 31 }
169
- its(:total_pages) { should == 3 }
170
- end
171
-
172
- context 'for association' do
173
- before do
174
- worker0 = User[0]
175
- 30.times do |i|
176
- worker0.projects << Project.create(:name => "Project#{i}")
177
- end
178
- worker0.projects.save
179
- end
180
-
181
- context 'on query' do
182
- subject { User[0].projects.page(3).all(:name.like => 'Project%').per(5) }
183
- its(:current_page) { should == 3 }
184
- its(:prev_page) { should == 2 }
185
- its(:next_page) { should == 4 }
186
- its('query.limit') { should == 5 }
187
- its('query.offset') { should == 10 }
188
- its(:total_count) { should == 30 }
189
- its(:total_pages) { should == 6 }
190
- end
191
-
192
- context 'after association conditions' do
193
- subject { User.page(3).all(:projects => Project.all).per(5) }
194
- its(:current_page) { should == 3 }
195
- its(:prev_page) { should == 2 }
196
- its(:next_page) { should == 4 }
197
- its('query.limit') { should == 5 }
198
- its('query.offset') { should == 10 }
199
- its(:total_count) { should == 30 }
200
- its(:total_pages) { should == 6 }
201
- end
202
- end
203
- end
204
- end
205
- end
@@ -1,84 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if defined? MongoMapper
4
- describe Kaminari::MongoMapperExtension do
5
- before(:each) do
6
- User.destroy_all
7
- 41.times { User.create!({:salary => 1}) }
8
- end
9
-
10
- describe '#page' do
11
- context 'page 1' do
12
- subject { User.page(1) }
13
- it { should be_a Plucky::Query }
14
- its(:current_page) { should == 1 }
15
- its(:prev_page) { should be_nil }
16
- its(:next_page) { should == 2 }
17
- its(:limit_value) { should == 25 }
18
- its(:total_pages) { should == 2 }
19
- it { should skip(0) }
20
- end
21
-
22
- context 'page 2' do
23
- subject { User.page 2 }
24
- it { should be_a Plucky::Query }
25
- its(:current_page) { should == 2 }
26
- its(:prev_page) { should == 1 }
27
- its(:next_page) { should be_nil }
28
- its(:limit_value) { should == 25 }
29
- its(:total_pages) { should == 2 }
30
- it { should skip 25 }
31
- end
32
-
33
- context 'page "foobar"' do
34
- subject { User.page 'foobar' }
35
- it { should be_a Plucky::Query }
36
- its(:current_page) { should == 1 }
37
- its(:prev_page) { should be_nil }
38
- its(:next_page) { should == 2 }
39
- its(:limit_value) { should == 25 }
40
- its(:total_pages) { should == 2 }
41
- it { should skip 0 }
42
- end
43
-
44
- context 'with criteria before' do
45
- it "should have the proper criteria source" do
46
- User.where(:salary => 1).page(2).criteria.source.should == {:salary => 1}
47
- end
48
-
49
- subject { User.where(:salary => 1).page 2 }
50
- its(:current_page) { should == 2 }
51
- its(:prev_page) { should == 1 }
52
- its(:next_page) { should be_nil }
53
- its(:limit_value) { should == 25 }
54
- its(:total_pages) { should == 2 }
55
- it { should skip 25 }
56
- end
57
-
58
- context 'with criteria after' do
59
- it "should have the proper criteria source" do
60
- User.where(:salary => 1).page(2).criteria.source.should == {:salary => 1}
61
- end
62
-
63
- subject { User.page(2).where(:salary => 1) }
64
- its(:current_page) { should == 2 }
65
- its(:prev_page) { should == 1 }
66
- its(:next_page) { should be_nil }
67
- its(:limit_value) { should == 25 }
68
- its(:total_pages) { should == 2 }
69
- it { should skip 25 }
70
- end
71
- end
72
-
73
- describe '#per' do
74
- subject { User.page(2).per(10) }
75
- it { should be_a Plucky::Query }
76
- its(:current_page) { should == 2 }
77
- its(:prev_page) { should == 1 }
78
- its(:next_page) { should == 3 }
79
- its(:limit_value) { should == 10 }
80
- its(:total_pages) { should == 5 }
81
- it { should skip 10 }
82
- end
83
- end
84
- end