kaminari 0.17.0 → 1.0.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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +26 -42
  4. data/CHANGELOG.md +566 -0
  5. data/CONTRIBUTING.md +16 -0
  6. data/Gemfile +1 -0
  7. data/README.md +545 -0
  8. data/Rakefile +21 -24
  9. data/gemfiles/active_record_41.gemfile +3 -4
  10. data/gemfiles/active_record_42.gemfile +3 -4
  11. data/gemfiles/active_record_50.gemfile +20 -0
  12. data/gemfiles/active_record_edge.gemfile +11 -7
  13. data/kaminari.gemspec +11 -17
  14. data/lib/kaminari/version.rb +2 -1
  15. data/lib/kaminari.rb +4 -39
  16. data/misc/bug_report_template.rb +57 -0
  17. metadata +41 -182
  18. data/.gemtest +0 -0
  19. data/.rspec +0 -2
  20. data/CHANGELOG.rdoc +0 -480
  21. data/README.rdoc +0 -336
  22. data/app/views/kaminari/_first_page.html.erb +0 -11
  23. data/app/views/kaminari/_first_page.html.haml +0 -9
  24. data/app/views/kaminari/_first_page.html.slim +0 -10
  25. data/app/views/kaminari/_gap.html.erb +0 -8
  26. data/app/views/kaminari/_gap.html.haml +0 -8
  27. data/app/views/kaminari/_gap.html.slim +0 -9
  28. data/app/views/kaminari/_last_page.html.erb +0 -11
  29. data/app/views/kaminari/_last_page.html.haml +0 -9
  30. data/app/views/kaminari/_last_page.html.slim +0 -10
  31. data/app/views/kaminari/_next_page.html.erb +0 -11
  32. data/app/views/kaminari/_next_page.html.haml +0 -9
  33. data/app/views/kaminari/_next_page.html.slim +0 -10
  34. data/app/views/kaminari/_page.html.erb +0 -12
  35. data/app/views/kaminari/_page.html.haml +0 -10
  36. data/app/views/kaminari/_page.html.slim +0 -11
  37. data/app/views/kaminari/_paginator.html.erb +0 -23
  38. data/app/views/kaminari/_paginator.html.haml +0 -18
  39. data/app/views/kaminari/_paginator.html.slim +0 -19
  40. data/app/views/kaminari/_prev_page.html.erb +0 -11
  41. data/app/views/kaminari/_prev_page.html.haml +0 -9
  42. data/app/views/kaminari/_prev_page.html.slim +0 -10
  43. data/config/locales/kaminari.yml +0 -19
  44. data/gemfiles/active_record_30.gemfile +0 -28
  45. data/gemfiles/active_record_31.gemfile +0 -26
  46. data/gemfiles/active_record_32.gemfile +0 -25
  47. data/gemfiles/active_record_40.gemfile +0 -26
  48. data/gemfiles/data_mapper_12.gemfile +0 -32
  49. data/gemfiles/mongo_mapper.gemfile +0 -25
  50. data/gemfiles/mongoid_30.gemfile +0 -22
  51. data/gemfiles/mongoid_31.gemfile +0 -21
  52. data/gemfiles/mongoid_40.gemfile +0 -19
  53. data/gemfiles/mongoid_50.gemfile +0 -23
  54. data/gemfiles/sinatra_13.gemfile +0 -36
  55. data/gemfiles/sinatra_14.gemfile +0 -33
  56. data/lib/generators/kaminari/config_generator.rb +0 -16
  57. data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
  58. data/lib/generators/kaminari/views_generator.rb +0 -119
  59. data/lib/kaminari/config.rb +0 -51
  60. data/lib/kaminari/engine.rb +0 -4
  61. data/lib/kaminari/grape.rb +0 -4
  62. data/lib/kaminari/helpers/action_view_extension.rb +0 -132
  63. data/lib/kaminari/helpers/paginator.rb +0 -195
  64. data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
  65. data/lib/kaminari/helpers/tags.rb +0 -108
  66. data/lib/kaminari/hooks.rb +0 -53
  67. data/lib/kaminari/models/active_record_extension.rb +0 -22
  68. data/lib/kaminari/models/active_record_model_extension.rb +0 -22
  69. data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
  70. data/lib/kaminari/models/array_extension.rb +0 -66
  71. data/lib/kaminari/models/configuration_methods.rb +0 -48
  72. data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
  73. data/lib/kaminari/models/data_mapper_extension.rb +0 -51
  74. data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
  75. data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
  76. data/lib/kaminari/models/mongoid_extension.rb +0 -26
  77. data/lib/kaminari/models/page_scope_methods.rb +0 -73
  78. data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
  79. data/lib/kaminari/railtie.rb +0 -7
  80. data/lib/kaminari/sinatra.rb +0 -7
  81. data/spec/config/config_spec.rb +0 -91
  82. data/spec/fake_app/active_record/config.rb +0 -3
  83. data/spec/fake_app/active_record/models.rb +0 -65
  84. data/spec/fake_app/data_mapper/config.rb +0 -1
  85. data/spec/fake_app/data_mapper/models.rb +0 -27
  86. data/spec/fake_app/mongo_mapper/config.rb +0 -2
  87. data/spec/fake_app/mongo_mapper/models.rb +0 -9
  88. data/spec/fake_app/mongoid/config.rb +0 -20
  89. data/spec/fake_app/mongoid/models.rb +0 -38
  90. data/spec/fake_app/rails_app.rb +0 -56
  91. data/spec/fake_app/sinatra_app.rb +0 -22
  92. data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
  93. data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
  94. data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
  95. data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
  96. data/spec/fake_gem.rb +0 -20
  97. data/spec/generators/views_generator_spec.rb +0 -18
  98. data/spec/helpers/action_view_extension_spec.rb +0 -318
  99. data/spec/helpers/helpers_spec.rb +0 -144
  100. data/spec/helpers/sinatra_helpers_spec.rb +0 -223
  101. data/spec/helpers/tags_spec.rb +0 -140
  102. data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
  103. data/spec/models/active_record/inherited_spec.rb +0 -9
  104. data/spec/models/active_record/scopes_spec.rb +0 -265
  105. data/spec/models/array_spec.rb +0 -172
  106. data/spec/models/configuration_methods_spec.rb +0 -125
  107. data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
  108. data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
  109. data/spec/models/mongoid/mongoid_spec.rb +0 -228
  110. data/spec/requests/users_spec.rb +0 -53
  111. data/spec/spec_helper.rb +0 -34
  112. data/spec/spec_helper_for_sinatra.rb +0 -34
  113. data/spec/support/database_cleaner.rb +0 -19
  114. data/spec/support/matchers.rb +0 -52
@@ -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
@@ -1,228 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if defined? Mongoid
4
- describe Kaminari::MongoidCriteriaMethods do
5
- describe "#total_count" do
6
- before do
7
- 2.times {|i| User.create!(:salary => i) }
8
- end
9
-
10
- context "when the scope is cloned" do
11
- it "should reset total_coount momoization" do
12
- User.page.tap(&:total_count).where(:salary => 1).total_count.should == 1
13
- end
14
- end
15
- end
16
- end
17
-
18
- describe Kaminari::MongoidExtension do
19
- before(:each) do
20
- 41.times do
21
- User.create!({:salary => 1})
22
- end
23
- end
24
-
25
- describe 'max_scan', :if => Mongoid::VERSION >= '3' do
26
- context 'less than total' do
27
- context 'page 1' do
28
- subject { User.max_scan(20).page 1 }
29
- it { should be_a Mongoid::Criteria }
30
- its(:current_page) { should == 1 }
31
- its(:prev_page) { should be_nil }
32
- its(:next_page) { should be_nil }
33
- its(:limit_value) { should == 25 }
34
- its(:total_pages) { should == 1 }
35
- its(:total_count) { should == 20 }
36
- it { should skip(0) }
37
- end
38
-
39
- context 'page 2' do
40
- subject { User.max_scan(30).page 2 }
41
- it { should be_a Mongoid::Criteria }
42
- its(:current_page) { should == 2 }
43
- its(:prev_page) { should == 1 }
44
- its(:next_page) { should be_nil }
45
- its(:limit_value) { should == 25 }
46
- its(:total_pages) { should == 2 }
47
- its(:total_count) { should == 30 }
48
- it { should skip 25 }
49
- end
50
- end
51
-
52
- context 'more than total' do
53
- context 'page 1' do
54
- subject { User.max_scan(60).page 1 }
55
- it { should be_a Mongoid::Criteria }
56
- its(:current_page) { should == 1 }
57
- its(:prev_page) { should be_nil }
58
- its(:next_page) { should == 2 }
59
- its(:limit_value) { should == 25 }
60
- its(:total_pages) { should == 2 }
61
- its(:total_count) { should == 41 }
62
- it { should skip(0) }
63
- end
64
-
65
- context 'page 2' do
66
- subject { User.max_scan(60).page 2 }
67
- it { should be_a Mongoid::Criteria }
68
- its(:current_page) { should == 2 }
69
- its(:prev_page) { should == 1 }
70
- its(:next_page) { should be_nil }
71
- its(:limit_value) { should == 25 }
72
- its(:total_pages) { should == 2 }
73
- its(:total_count) { should == 41 }
74
- it { should skip 25 }
75
- end
76
- end
77
- end
78
-
79
- describe '#page' do
80
-
81
- context 'page 1' do
82
- subject { User.page 1 }
83
- it { should be_a Mongoid::Criteria }
84
- its(:current_page) { should == 1 }
85
- its(:prev_page) { should be_nil }
86
- its(:next_page) { should == 2 }
87
- its(:limit_value) { should == 25 }
88
- its(:total_pages) { should == 2 }
89
- it { should skip(0) }
90
- end
91
-
92
- context 'page 2' do
93
- subject { User.page 2 }
94
- it { should be_a Mongoid::Criteria }
95
- its(:current_page) { should == 2 }
96
- its(:prev_page) { should == 1 }
97
- its(:next_page) { should be_nil }
98
- its(:limit_value) { should == 25 }
99
- its(:total_pages) { should == 2 }
100
- it { should skip 25 }
101
- end
102
-
103
- context 'page "foobar"' do
104
- subject { User.page 'foobar' }
105
- it { should be_a Mongoid::Criteria }
106
- its(:current_page) { should == 1 }
107
- its(:prev_page) { should be_nil }
108
- its(:next_page) { should == 2 }
109
- its(:limit_value) { should == 25 }
110
- its(:total_pages) { should == 2 }
111
- it { should skip 0 }
112
- end
113
-
114
- shared_examples 'complete valid pagination' do
115
- if Mongoid::VERSION > '3.0.0'
116
- its(:selector) { should == {'salary' => 1} }
117
- else
118
- its(:selector) { should == {:salary => 1} }
119
- end
120
- its(:current_page) { should == 2 }
121
- its(:prev_page) { should == 1 }
122
- its(:next_page) { should be_nil }
123
- its(:limit_value) { should == 25 }
124
- its(:total_pages) { should == 2 }
125
- it { should skip 25 }
126
- end
127
-
128
- context 'with criteria before' do
129
- subject { User.where(:salary => 1).page 2 }
130
- it_should_behave_like 'complete valid pagination'
131
- end
132
-
133
- context 'with criteria after' do
134
- subject { User.page(2).where(:salary => 1) }
135
- it_should_behave_like 'complete valid pagination'
136
- end
137
-
138
- context "with database:", :if => Mongoid::VERSION >= '3' do
139
- before :all do
140
- 15.times { User.with(:database => "default_db").create!(:salary => 1) }
141
- 10.times { User.with(:database => "other_db").create!(:salary => 1) }
142
- end
143
-
144
- context "default_db" do
145
- subject { User.with(:database => "default_db").order_by(:artist.asc).page(1) }
146
- its(:total_count) { should == 15 }
147
- end
148
-
149
- context "other_db" do
150
- subject { User.with(:database => "other_db").order_by(:artist.asc).page(1) }
151
- its(:total_count) { should == 10 }
152
- end
153
- end
154
- end
155
-
156
- describe '#per' do
157
- subject { User.page(2).per(10) }
158
- it { should be_a Mongoid::Criteria }
159
- its(:current_page) { should == 2 }
160
- its(:prev_page) { should == 1 }
161
- its(:next_page) { should == 3 }
162
- its(:limit_value) { should == 10 }
163
- its(:total_pages) { should == 5 }
164
- it { should skip 10 }
165
- end
166
-
167
- describe '#page in embedded documents' do
168
- before do
169
- @mongo_developer = MongoMongoidExtensionDeveloper.new
170
- @mongo_developer.frameworks.new(:name => "rails", :language => "ruby")
171
- @mongo_developer.frameworks.new(:name => "merb", :language => "ruby")
172
- @mongo_developer.frameworks.new(:name => "sinatra", :language => "ruby")
173
- @mongo_developer.frameworks.new(:name => "cakephp", :language => "php")
174
- @mongo_developer.frameworks.new(:name => "tornado", :language => "python")
175
- end
176
-
177
- context 'page 1' do
178
- subject { @mongo_developer.frameworks.page(1).per(1) }
179
- it { should be_a Mongoid::Criteria }
180
- its(:total_count) { should == 5 }
181
- its(:limit_value) { should == 1 }
182
- its(:current_page) { should == 1 }
183
- its(:prev_page) { should be_nil }
184
- its(:next_page) { should == 2 }
185
- its(:total_pages) { should == 5 }
186
- end
187
-
188
- context 'with criteria after' do
189
- subject { @mongo_developer.frameworks.page(1).per(2).where(:language => "ruby") }
190
- it { should be_a Mongoid::Criteria }
191
- its(:total_count) { should == 3 }
192
- its(:limit_value) { should == 2 }
193
- its(:current_page) { should == 1 }
194
- its(:prev_page) { should be_nil }
195
- its(:next_page) { should == 2 }
196
- its(:total_pages) { should == 2 }
197
- end
198
-
199
- context 'with criteria before' do
200
- subject { @mongo_developer.frameworks.where(:language => "ruby").page(1).per(2) }
201
- it { should be_a Mongoid::Criteria }
202
- its(:total_count) { should == 3 }
203
- its(:limit_value) { should == 2 }
204
- its(:current_page) { should == 1 }
205
- its(:prev_page) { should be_nil }
206
- its(:next_page) { should == 2 }
207
- its(:total_pages) { should == 2 }
208
- end
209
- end
210
-
211
- describe '#paginates_per' do
212
- context 'when paginates_per is not defined in superclass' do
213
- subject { Product.all.page 1 }
214
- its(:limit_value) { should == 25 }
215
- end
216
-
217
- context 'when paginates_per is defined in subclass' do
218
- subject { Device.all.page 1 }
219
- its(:limit_value) { should == 100 }
220
- end
221
-
222
- context 'when paginates_per is defined in subclass of subclass' do
223
- subject { Android.all.page 1 }
224
- its(:limit_value) { should == 200 }
225
- end
226
- end
227
- end
228
- end
@@ -1,53 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- feature 'Users' do
5
- background do
6
- 1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}" }
7
- end
8
- scenario 'navigating by pagination links' do
9
- visit '/users'
10
-
11
- within 'nav.pagination' do
12
- within 'span.page.current' do
13
- page.should have_content '1'
14
- end
15
- within 'span.next' do
16
- click_link 'Next ›'
17
- end
18
- end
19
-
20
- within 'nav.pagination' do
21
- within 'span.page.current' do
22
- page.should have_content '2'
23
- end
24
- within 'span.last' do
25
- click_link 'Last »'
26
- end
27
- end
28
-
29
- within 'nav.pagination' do
30
- within 'span.page.current' do
31
- page.should have_content '4'
32
- end
33
- within 'span.prev' do
34
- click_link '‹ Prev'
35
- end
36
- end
37
-
38
- within 'nav.pagination' do
39
- within 'span.page.current' do
40
- page.should have_content '3'
41
- end
42
- within 'span.first' do
43
- click_link '« First'
44
- end
45
- end
46
-
47
- within 'nav.pagination' do
48
- within 'span.page.current' do
49
- page.should have_content '1'
50
- end
51
- end
52
- end
53
- end
data/spec/spec_helper.rb DELETED
@@ -1,34 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
-
4
- begin
5
- require 'rails'
6
- rescue LoadError
7
- end
8
-
9
- require 'bundler/setup'
10
- Bundler.require
11
-
12
- require 'capybara/rspec'
13
- require 'database_cleaner'
14
-
15
- # Simulate a gem providing a subclass of ActiveRecord::Base before the Railtie is loaded.
16
- require 'fake_gem' if defined? ActiveRecord
17
-
18
- if defined? Rails
19
- require 'fake_app/rails_app'
20
-
21
- require 'rspec/rails'
22
- end
23
- if defined? Sinatra
24
- require 'spec_helper_for_sinatra'
25
- end
26
-
27
- # Requires supporting files with custom matchers and macros, etc,
28
- # in ./support/ and its subdirectories.
29
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
30
-
31
- RSpec.configure do |config|
32
- config.mock_with :rr
33
- config.filter_run_excluding :generator_spec => true if !ENV['GENERATOR_SPEC']
34
- end
@@ -1,34 +0,0 @@
1
- require 'kaminari/sinatra'
2
- require 'kaminari/helpers/action_view_extension'
3
- require 'rack/test'
4
- require 'sinatra/test_helpers'
5
- require 'capybara/rspec'
6
-
7
- require 'fake_app/sinatra_app'
8
-
9
- Capybara.app = SinatraApp
10
-
11
- module HelperMethodForHelperSpec
12
- module FakeEnv
13
- def env
14
- {'PATH_INFO' => '/'}
15
- end
16
- end
17
-
18
- def helper
19
- # OMG terrible object...
20
- ::Kaminari::Helpers::SinatraHelpers::ActionViewTemplateProxy.new(:current_params => {}, :current_path => '/', :param_name => Kaminari.config.param_name).extend(Padrino::Helpers, Kaminari::ActionViewExtension, Kaminari::Helpers::SinatraHelpers::HelperMethods, FakeEnv)
21
- end
22
- end
23
-
24
- RSpec.configure do |config|
25
- config.include Rack::Test::Methods
26
- config.include Sinatra::TestHelpers
27
- config.include HelperMethodForHelperSpec
28
- # config.include HelperMethodForHelperSpec, :type => :helper
29
- end
30
-
31
- require 'nokogiri'
32
- def last_document
33
- Nokogiri::HTML(last_response.body)
34
- end
@@ -1,19 +0,0 @@
1
- DatabaseCleaner[:active_record].strategy = :transaction if defined? ActiveRecord
2
- DatabaseCleaner[:data_mapper].strategy = :truncation if defined? DataMapper
3
- DatabaseCleaner[:mongoid].strategy = :truncation if defined? Mongoid
4
- DatabaseCleaner[:mongo_mapper].strategy = :truncation if defined? MongoMapper
5
-
6
- RSpec.configure do |config|
7
- config.before :suite do
8
- DatabaseCleaner.clean_with :truncation if defined? ActiveRecord
9
- DatabaseCleaner.clean_with :truncation if defined? DataMapper
10
- DatabaseCleaner.clean_with :truncation if defined? Mongoid
11
- DatabaseCleaner.clean_with :truncation if defined? MongoMapper
12
- end
13
- config.before :each do
14
- DatabaseCleaner.start
15
- end
16
- config.after :each do
17
- DatabaseCleaner.clean
18
- end
19
- end