bootstrap_pager 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/pager.iml +50 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +307 -0
- data/Rakefile +42 -0
- data/app/assets/javascripts/infinitescroll.js +8 -0
- data/app/helpers/pager_helper.rb +5 -0
- data/app/views/pager/_first_page.html.erb +11 -0
- data/app/views/pager/_first_page.html.haml +9 -0
- data/app/views/pager/_first_page.html.slim +10 -0
- data/app/views/pager/_gap.html.erb +8 -0
- data/app/views/pager/_gap.html.haml +8 -0
- data/app/views/pager/_gap.html.slim +10 -0
- data/app/views/pager/_last_page.html.erb +11 -0
- data/app/views/pager/_last_page.html.haml +9 -0
- data/app/views/pager/_last_page.html.slim +10 -0
- data/app/views/pager/_next_page.html.erb +11 -0
- data/app/views/pager/_next_page.html.haml +9 -0
- data/app/views/pager/_next_page.html.slim +10 -0
- data/app/views/pager/_page.html.erb +14 -0
- data/app/views/pager/_page.html.haml +11 -0
- data/app/views/pager/_page.html.slim +13 -0
- data/app/views/pager/_paginator.html.erb +25 -0
- data/app/views/pager/_paginator.html.haml +19 -0
- data/app/views/pager/_paginator.html.slim +20 -0
- data/app/views/pager/_prev_page.html.erb +11 -0
- data/app/views/pager/_prev_page.html.haml +9 -0
- data/app/views/pager/_prev_page.html.slim +10 -0
- data/bootstrap_pager.gemspec +36 -0
- data/config/locales/pager.yml +19 -0
- data/gemfiles/active_record_30.gemfile +9 -0
- data/gemfiles/active_record_31.gemfile +7 -0
- data/gemfiles/active_record_32.gemfile +10 -0
- data/gemfiles/active_record_40.gemfile +8 -0
- data/gemfiles/active_record_edge.gemfile +11 -0
- data/gemfiles/data_mapper_12.gemfile +15 -0
- data/gemfiles/mongo_mapper.gemfile +10 -0
- data/gemfiles/mongoid_24.gemfile +7 -0
- data/gemfiles/mongoid_30.gemfile +12 -0
- data/gemfiles/sinatra_13.gemfile +13 -0
- data/gemfiles/sinatra_14.gemfile +13 -0
- data/lib/bootstrap_pager/config.rb +51 -0
- data/lib/bootstrap_pager/grape.rb +4 -0
- data/lib/bootstrap_pager/helpers/action_view_extension.rb +152 -0
- data/lib/bootstrap_pager/helpers/paginator.rb +186 -0
- data/lib/bootstrap_pager/helpers/sinatra_helpers.rb +144 -0
- data/lib/bootstrap_pager/helpers/tags.rb +96 -0
- data/lib/bootstrap_pager/hooks.rb +41 -0
- data/lib/bootstrap_pager/models/active_record_extension.rb +22 -0
- data/lib/bootstrap_pager/models/active_record_model_extension.rb +20 -0
- data/lib/bootstrap_pager/models/active_record_relation_methods.rb +29 -0
- data/lib/bootstrap_pager/models/array_extension.rb +58 -0
- data/lib/bootstrap_pager/models/configuration_methods.rb +48 -0
- data/lib/bootstrap_pager/models/data_mapper_collection_methods.rb +15 -0
- data/lib/bootstrap_pager/models/data_mapper_extension.rb +48 -0
- data/lib/bootstrap_pager/models/mongo_mapper_extension.rb +18 -0
- data/lib/bootstrap_pager/models/mongoid_criteria_methods.rb +23 -0
- data/lib/bootstrap_pager/models/mongoid_extension.rb +33 -0
- data/lib/bootstrap_pager/models/page_scope_methods.rb +70 -0
- data/lib/bootstrap_pager/models/plucky_criteria_methods.rb +18 -0
- data/lib/bootstrap_pager/railtie.rb +7 -0
- data/lib/bootstrap_pager/sinatra.rb +5 -0
- data/lib/bootstrap_pager/version.rb +3 -0
- data/lib/bootstrap_pager.rb +38 -0
- data/lib/generators/pager/config_generator.rb +16 -0
- data/lib/generators/pager/templates/pager_config.rb +10 -0
- data/lib/generators/pager/views_generator.rb +118 -0
- data/spec/config/config_spec.rb +91 -0
- data/spec/fake_app/active_record/config.rb +3 -0
- data/spec/fake_app/active_record/models.rb +57 -0
- data/spec/fake_app/data_mapper/config.rb +7 -0
- data/spec/fake_app/data_mapper/models.rb +27 -0
- data/spec/fake_app/log/development.log +832 -0
- data/spec/fake_app/mongo_mapper/config.rb +2 -0
- data/spec/fake_app/mongo_mapper/models.rb +9 -0
- data/spec/fake_app/mongoid/config.rb +16 -0
- data/spec/fake_app/mongoid/models.rb +22 -0
- data/spec/fake_app/rails_app.rb +67 -0
- data/spec/fake_app/sinatra_app.rb +22 -0
- data/spec/fake_gem.rb +4 -0
- data/spec/helpers/action_view_extension_spec.rb +292 -0
- data/spec/helpers/helpers_spec.rb +135 -0
- data/spec/helpers/sinatra_helpers_spec.rb +170 -0
- data/spec/helpers/tags_spec.rb +140 -0
- data/spec/models/active_record/active_record_relation_methods_spec.rb +47 -0
- data/spec/models/active_record/default_per_page_spec.rb +32 -0
- data/spec/models/active_record/max_pages_spec.rb +23 -0
- data/spec/models/active_record/max_per_page_spec.rb +32 -0
- data/spec/models/active_record/scopes_spec.rb +242 -0
- data/spec/models/array_spec.rb +150 -0
- data/spec/models/data_mapper/data_mapper_spec.rb +207 -0
- data/spec/models/mongo_mapper/mongo_mapper_spec.rb +84 -0
- data/spec/models/mongoid/mongoid_spec.rb +126 -0
- data/spec/requests/users_spec.rb +53 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/spec_helper_for_sinatra.rb +34 -0
- data/spec/support/database_cleaner.rb +16 -0
- data/spec/support/matchers.rb +52 -0
- data/vendor/assets/javascripts/jquery.infinitescroll.js +814 -0
- data/vendor/assets/javascripts/jquery.infinitescroll.min.js +1 -0
- metadata +311 -0
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BootstrapPager::PaginatableArray do
|
4
|
+
it { should have(0).items }
|
5
|
+
|
6
|
+
context 'specifying limit and offset when initializing' do
|
7
|
+
subject { BootstrapPager::PaginatableArray.new((1..100).to_a, :limit => 10, :offset => 20) }
|
8
|
+
its(:current_page) { should == 3 }
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:array) { BootstrapPager::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
|
+
subject { BootstrapPager::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 }
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
if defined? DataMapper
|
4
|
+
# tests for issue #203
|
5
|
+
describe BootstrapPager::DataMapperCollectionMethods do
|
6
|
+
before do
|
7
|
+
100.times do |i|
|
8
|
+
User.create(:name => "User#{i}", :age => i)
|
9
|
+
end
|
10
|
+
|
11
|
+
worker0 = User[0]
|
12
|
+
50.times do |i|
|
13
|
+
worker0.projects << Project.create(:name => "Project#{i}")
|
14
|
+
end
|
15
|
+
worker0.projects.save
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Model' do
|
19
|
+
subject { User }
|
20
|
+
its(:current_page) { should == 1 }
|
21
|
+
it { User.all.count.should == 100 }
|
22
|
+
it { User.page(1).length.should == 25 }
|
23
|
+
it {
|
24
|
+
User.paginates_per(5)
|
25
|
+
User.page(1).length.should == 5
|
26
|
+
User.all.page(1).length.should == 5
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe BootstrapPager::DataMapperExtension do
|
33
|
+
before do
|
34
|
+
100.times do |i|
|
35
|
+
User.create(:name => "User#{i}", :age => i)
|
36
|
+
end
|
37
|
+
|
38
|
+
worker0 = User[0]
|
39
|
+
50.times do |i|
|
40
|
+
worker0.projects << Project.create(:name => "Project#{i}")
|
41
|
+
end
|
42
|
+
worker0.projects.save
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'Collection' do
|
46
|
+
subject{ User.all }
|
47
|
+
it { should respond_to(:page) }
|
48
|
+
it { should_not respond_to(:per) }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'Model' do
|
52
|
+
subject{ User }
|
53
|
+
it { should respond_to(:page) }
|
54
|
+
it { should respond_to(:default_per_page) }
|
55
|
+
it { should_not respond_to(:per) }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#page' do
|
59
|
+
context 'page 0' do
|
60
|
+
subject { User.all(:age.gte => 60).page 0 }
|
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 == User.count(:age.gte => 60) }
|
68
|
+
its(:total_pages) { should == 2 }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'page 1' do
|
72
|
+
subject { User.all(:age.gte => 0).page 1 }
|
73
|
+
it { should be_a DataMapper::Collection }
|
74
|
+
its(:current_page) { should == 1 }
|
75
|
+
its(:prev_page) { should be_nil }
|
76
|
+
its(:next_page) { should == 2 }
|
77
|
+
its('query.limit') { should == 25 }
|
78
|
+
its('query.offset') { should == 0 }
|
79
|
+
its(:total_count) { should == 100 }
|
80
|
+
its(:total_pages) { should == 4 }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'page 2' do
|
84
|
+
subject { User.page 2 }
|
85
|
+
it { should be_a DataMapper::Collection }
|
86
|
+
its(:current_page) { should == 2 }
|
87
|
+
its(:prev_page) { should == 1 }
|
88
|
+
its(:next_page) { should == 3 }
|
89
|
+
its(:limit_value) { should == 25 }
|
90
|
+
its('query.limit') { should == 25 }
|
91
|
+
its('query.offset') { should == 25 }
|
92
|
+
its(:total_count) { should == 100 }
|
93
|
+
its(:total_pages) { should == 4 }
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'page "foobar"' do
|
97
|
+
subject { User.page 'foobar' }
|
98
|
+
it { should be_a DataMapper::Collection }
|
99
|
+
its(:current_page) { should == 1 }
|
100
|
+
its(:prev_page) { should be_nil }
|
101
|
+
its(:next_page) { should == 2 }
|
102
|
+
its('query.limit') { should == 25 }
|
103
|
+
its('query.offset') { should == 0 }
|
104
|
+
its(:total_count) { should == 100 }
|
105
|
+
its(:total_pages) { should == 4 }
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'with criteria before' do
|
109
|
+
subject { User.all(:age.gt => 60).page 2 }
|
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
|
+
|
120
|
+
context 'with criteria after' do
|
121
|
+
subject { User.page(2).all(:age.gt => 60) }
|
122
|
+
it { should be_a DataMapper::Collection }
|
123
|
+
its(:current_page) { should == 2 }
|
124
|
+
its(:prev_page) { should == 1 }
|
125
|
+
its(:next_page) { should be_nil }
|
126
|
+
its('query.limit') { should == 25 }
|
127
|
+
its('query.offset') { should == 25 }
|
128
|
+
its(:total_count) { should == User.count(:age.gt => 60) }
|
129
|
+
its(:total_pages) { should == 2 }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#per' do
|
134
|
+
context 'on simple query' do
|
135
|
+
subject { User.page(2).per(20) }
|
136
|
+
it { should be_a DataMapper::Collection }
|
137
|
+
its(:current_page) { should == 2 }
|
138
|
+
its(:prev_page) { should == 1 }
|
139
|
+
its(:next_page) { should == 3 }
|
140
|
+
its('query.limit') { should == 20 }
|
141
|
+
its(:limit_value) { should == 20 }
|
142
|
+
its('query.offset') { should == 20 }
|
143
|
+
its(:total_count) { should == 100 }
|
144
|
+
its(:total_pages) { should == 5 }
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'on query with condition' do
|
148
|
+
subject { User.page(5).all(:age.lte => 80).per(13) }
|
149
|
+
its(:current_page) { should == 5 }
|
150
|
+
its(:prev_page) { should == 4 }
|
151
|
+
its(:next_page) { should == 6 }
|
152
|
+
its('query.limit') { should == 13 }
|
153
|
+
its('query.offset') { should == 52 }
|
154
|
+
its(:total_count) { should == 81 }
|
155
|
+
its(:total_pages) { should == 7 }
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'on query with order' do
|
159
|
+
subject { User.page(5).all(:age.lte => 80, :order => [:age.asc]).per(13) }
|
160
|
+
it('includes user with age 52') { should include(User.first(:age => 52)) }
|
161
|
+
it('does not include user with age 51') { should_not include(User.first(:age => 51)) }
|
162
|
+
it('includes user with age 52') { should include(User.first(:age => 64)) }
|
163
|
+
it('does not include user with age 51') { should_not include(User.first(:age => 65)) }
|
164
|
+
its(:current_page) { should == 5 }
|
165
|
+
its(:prev_page) { should == 4 }
|
166
|
+
its(:next_page) { should == 6 }
|
167
|
+
its('query.limit') { should == 13 }
|
168
|
+
its('query.offset') { should == 52 }
|
169
|
+
its(:total_count) { should == 81 }
|
170
|
+
its(:total_pages) { should == 7 }
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'on chained queries' do
|
174
|
+
subject { User.all(:age.gte => 50).page(3).all(:age.lte => 80).per(13) }
|
175
|
+
its(:current_page) { should == 3 }
|
176
|
+
its(:prev_page) { should == 2 }
|
177
|
+
its(:next_page) { should be_nil }
|
178
|
+
its('query.limit') { should == 13 }
|
179
|
+
its('query.offset') { should == 26 }
|
180
|
+
its(:total_count) { should == 31 }
|
181
|
+
its(:total_pages) { should == 3 }
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'on query on association' do
|
185
|
+
subject { User[0].projects.page(3).all(:name.like => 'Project%').per(5) }
|
186
|
+
its(:current_page) { should == 3 }
|
187
|
+
its(:prev_page) { should == 2 }
|
188
|
+
its(:next_page) { should == 4 }
|
189
|
+
its('query.limit') { should == 5 }
|
190
|
+
its('query.offset') { should == 10 }
|
191
|
+
its(:total_count) { should == 50 }
|
192
|
+
its(:total_pages) { should == 10 }
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'on query with association conditions' do
|
196
|
+
subject { User.page(3).all(:projects => Project.all).per(5) }
|
197
|
+
its(:current_page) { should == 3 }
|
198
|
+
its(:prev_page) { should == 2 }
|
199
|
+
its(:next_page) { should == 4 }
|
200
|
+
its('query.limit') { should == 5 }
|
201
|
+
its('query.offset') { should == 10 }
|
202
|
+
its(:total_count) { should == 50 }
|
203
|
+
its(:total_pages) { should == 10 }
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
if defined? MongoMapper
|
4
|
+
describe BootstrapPager::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
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
if defined? Mongoid
|
4
|
+
describe BootstrapPager::MongoidExtension do
|
5
|
+
before(:each) do
|
6
|
+
41.times do
|
7
|
+
User.create!({:salary => 1})
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#page' do
|
12
|
+
|
13
|
+
context 'page 1' do
|
14
|
+
subject { User.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 == 2 }
|
19
|
+
its(:limit_value) { should == 25 }
|
20
|
+
its(:total_pages) { should == 2 }
|
21
|
+
it { should skip(0) }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'page 2' do
|
25
|
+
subject { User.page 2 }
|
26
|
+
it { should be_a Mongoid::Criteria }
|
27
|
+
its(:current_page) { should == 2 }
|
28
|
+
its(:prev_page) { should == 1 }
|
29
|
+
its(:next_page) { should be_nil }
|
30
|
+
its(:limit_value) { should == 25 }
|
31
|
+
its(:total_pages) { should == 2 }
|
32
|
+
it { should skip 25 }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'page "foobar"' do
|
36
|
+
subject { User.page 'foobar' }
|
37
|
+
it { should be_a Mongoid::Criteria }
|
38
|
+
its(:current_page) { should == 1 }
|
39
|
+
its(:prev_page) { should be_nil }
|
40
|
+
its(:next_page) { should == 2 }
|
41
|
+
its(:limit_value) { should == 25 }
|
42
|
+
its(:total_pages) { should == 2 }
|
43
|
+
it { should skip 0 }
|
44
|
+
end
|
45
|
+
|
46
|
+
shared_examples 'complete valid pagination' do
|
47
|
+
if Mongoid::VERSION =~ /^3/
|
48
|
+
its(:selector) { should == {'salary' => 1} }
|
49
|
+
else
|
50
|
+
its(:selector) { should == {:salary => 1} }
|
51
|
+
end
|
52
|
+
its(:current_page) { should == 2 }
|
53
|
+
its(:prev_page) { should == 1 }
|
54
|
+
its(:next_page) { should be_nil }
|
55
|
+
its(:limit_value) { should == 25 }
|
56
|
+
its(:total_pages) { should == 2 }
|
57
|
+
it { should skip 25 }
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with criteria before' do
|
61
|
+
subject { User.where(:salary => 1).page 2 }
|
62
|
+
it_should_behave_like 'complete valid pagination'
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'with criteria after' do
|
66
|
+
subject { User.page(2).where(:salary => 1) }
|
67
|
+
it_should_behave_like 'complete valid pagination'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#per' do
|
72
|
+
subject { User.page(2).per(10) }
|
73
|
+
it { should be_a Mongoid::Criteria }
|
74
|
+
its(:current_page) { should == 2 }
|
75
|
+
its(:prev_page) { should == 1 }
|
76
|
+
its(:next_page) { should == 3 }
|
77
|
+
its(:limit_value) { should == 10 }
|
78
|
+
its(:total_pages) { should == 5 }
|
79
|
+
it { should skip 10 }
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#page in embedded documents' do
|
83
|
+
before do
|
84
|
+
@mongo_developer = MongoMongoidExtensionDeveloper.new
|
85
|
+
@mongo_developer.frameworks.new(:name => "rails", :language => "ruby")
|
86
|
+
@mongo_developer.frameworks.new(:name => "merb", :language => "ruby")
|
87
|
+
@mongo_developer.frameworks.new(:name => "sinatra", :language => "ruby")
|
88
|
+
@mongo_developer.frameworks.new(:name => "cakephp", :language => "php")
|
89
|
+
@mongo_developer.frameworks.new(:name => "tornado", :language => "python")
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'page 1' do
|
93
|
+
subject { @mongo_developer.frameworks.page(1).per(1) }
|
94
|
+
it { should be_a Mongoid::Criteria }
|
95
|
+
its(:total_count) { should == 5 }
|
96
|
+
its(:limit_value) { should == 1 }
|
97
|
+
its(:current_page) { should == 1 }
|
98
|
+
its(:prev_page) { should be_nil }
|
99
|
+
its(:next_page) { should == 2 }
|
100
|
+
its(:total_pages) { should == 5 }
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'with criteria after' do
|
104
|
+
subject { @mongo_developer.frameworks.page(1).per(2).where(:language => "ruby") }
|
105
|
+
it { should be_a Mongoid::Criteria }
|
106
|
+
its(:total_count) { should == 3 }
|
107
|
+
its(:limit_value) { should == 2 }
|
108
|
+
its(:current_page) { should == 1 }
|
109
|
+
its(:prev_page) { should be_nil }
|
110
|
+
its(:next_page) { should == 2 }
|
111
|
+
its(:total_pages) { should == 2 }
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'with criteria before' do
|
115
|
+
subject { @mongo_developer.frameworks.where(:language => "ruby").page(1).per(2) }
|
116
|
+
it { should be_a Mongoid::Criteria }
|
117
|
+
its(:total_count) { should == 3 }
|
118
|
+
its(:limit_value) { should == 2 }
|
119
|
+
its(:current_page) { should == 1 }
|
120
|
+
its(:prev_page) { should be_nil }
|
121
|
+
its(:next_page) { should == 2 }
|
122
|
+
its(:total_pages) { should == 2 }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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 'li.page.active' do
|
13
|
+
page.should have_content '1'
|
14
|
+
end
|
15
|
+
within 'li.next' do
|
16
|
+
click_link 'Next ›'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
within 'nav.pagination' do
|
21
|
+
within 'li.page.active' do
|
22
|
+
page.should have_content '2'
|
23
|
+
end
|
24
|
+
within 'li.last' do
|
25
|
+
click_link 'Last »'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
within 'nav.pagination' do
|
30
|
+
within 'li.page.active' do
|
31
|
+
page.should have_content '4'
|
32
|
+
end
|
33
|
+
within 'li.prev' do
|
34
|
+
click_link '‹ Prev'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
within 'nav.pagination' do
|
39
|
+
within 'li.page.active' do
|
40
|
+
page.should have_content '3'
|
41
|
+
end
|
42
|
+
within 'li.first' do
|
43
|
+
click_link '« First'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
within 'nav.pagination' do
|
48
|
+
within 'li.page.active' do
|
49
|
+
page.should have_content '1'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
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
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'bootstrap_pager/sinatra'
|
2
|
+
require 'bootstrap_pager/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
|
+
::BootstrapPager::Helpers::SinatraHelpers::ActionViewTemplateProxy.new(:current_params => {}, :current_path => '/', :param_name => BootstrapPager.config.param_name).extend(Padrino::Helpers, BootstrapPager::ActionViewExtension, BootstrapPager::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
|
@@ -0,0 +1,16 @@
|
|
1
|
+
DatabaseCleaner[:active_record].strategy = :transaction if defined? ActiveRecord
|
2
|
+
DatabaseCleaner[:data_mapper].strategy = :transaction 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 :transaction
|
9
|
+
end
|
10
|
+
config.before :each do
|
11
|
+
DatabaseCleaner.start
|
12
|
+
end
|
13
|
+
config.after :each do
|
14
|
+
DatabaseCleaner.clean
|
15
|
+
end
|
16
|
+
end
|