kaminari 0.13.0 → 0.14.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.
- data/.gitignore +2 -0
- data/.travis.yml +8 -1
- data/CHANGELOG +46 -10
- data/README.rdoc +14 -3
- data/Rakefile +22 -2
- data/app/views/kaminari/_first_page.html.erb +1 -1
- data/app/views/kaminari/_first_page.html.haml +1 -1
- data/app/views/kaminari/_first_page.html.slim +1 -1
- data/app/views/kaminari/_gap.html.erb +1 -1
- data/app/views/kaminari/_gap.html.haml +1 -1
- data/app/views/kaminari/_gap.html.slim +1 -1
- data/app/views/kaminari/_last_page.html.erb +1 -1
- data/app/views/kaminari/_last_page.html.haml +1 -1
- data/app/views/kaminari/_last_page.html.slim +1 -1
- data/app/views/kaminari/_next_page.html.erb +1 -1
- data/app/views/kaminari/_next_page.html.haml +1 -1
- data/app/views/kaminari/_next_page.html.slim +1 -1
- data/app/views/kaminari/_page.html.erb +2 -2
- data/app/views/kaminari/_page.html.haml +1 -1
- data/app/views/kaminari/_page.html.slim +1 -1
- data/app/views/kaminari/_paginator.html.erb +1 -1
- data/app/views/kaminari/_paginator.html.haml +1 -1
- data/app/views/kaminari/_paginator.html.slim +1 -1
- data/app/views/kaminari/_prev_page.html.erb +1 -1
- data/app/views/kaminari/_prev_page.html.haml +1 -1
- data/app/views/kaminari/_prev_page.html.slim +1 -1
- data/config/locales/kaminari.yml +9 -0
- data/gemfiles/active_record_30.gemfile +7 -0
- data/gemfiles/active_record_31.gemfile +7 -0
- data/gemfiles/active_record_32.gemfile +7 -0
- data/gemfiles/data_mapper_12.gemfile +12 -0
- data/gemfiles/mongo_mapper.gemfile +7 -0
- data/gemfiles/mongoid_24.gemfile +7 -0
- data/gemfiles/mongoid_30.gemfile +7 -0
- data/gemfiles/sinatra.gemfile +10 -0
- data/kaminari.gemspec +6 -18
- data/lib/generators/kaminari/templates/kaminari_config.rb +1 -0
- data/lib/kaminari.rb +22 -57
- data/lib/kaminari/config.rb +7 -1
- data/lib/kaminari/grape.rb +4 -0
- data/lib/kaminari/helpers/action_view_extension.rb +84 -13
- data/lib/kaminari/helpers/paginator.rb +8 -5
- data/lib/kaminari/helpers/sinatra_helpers.rb +25 -6
- data/lib/kaminari/helpers/tags.rb +1 -1
- data/lib/kaminari/hooks.rb +12 -10
- data/lib/kaminari/models/active_record_relation_methods.rb +0 -3
- data/lib/kaminari/models/configuration_methods.rb +15 -1
- data/lib/kaminari/models/page_scope_methods.rb +6 -2
- data/lib/kaminari/models/plucky_criteria_methods.rb +3 -0
- data/lib/kaminari/railtie.rb +2 -2
- data/lib/kaminari/sinatra.rb +2 -10
- data/lib/kaminari/version.rb +1 -1
- data/spec/config/config_spec.rb +15 -0
- data/spec/fake_app/active_record/config.rb +3 -0
- data/spec/{fake_app.rb → fake_app/active_record/models.rb} +7 -34
- data/spec/fake_app/data_mapper/config.rb +1 -0
- data/spec/fake_app/data_mapper/models.rb +27 -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 +55 -0
- data/spec/fake_app/sinatra_app.rb +22 -0
- data/spec/fake_gem.rb +0 -2
- data/spec/helpers/action_view_extension_spec.rb +192 -45
- data/spec/helpers/helpers_spec.rb +8 -8
- data/spec/helpers/sinatra_helpers_spec.rb +129 -133
- data/spec/helpers/tags_spec.rb +8 -8
- data/spec/models/active_record/active_record_relation_methods_spec.rb +30 -0
- data/spec/models/active_record/default_per_page_spec.rb +32 -0
- data/spec/models/active_record/max_per_page_spec.rb +32 -0
- data/spec/models/active_record/scopes_spec.rb +166 -0
- data/spec/models/array_spec.rb +7 -7
- data/spec/models/data_mapper/data_mapper_spec.rb +155 -0
- data/spec/models/mongo_mapper/mongo_mapper_spec.rb +72 -0
- data/spec/models/mongoid/mongoid_spec.rb +110 -0
- data/spec/requests/users_spec.rb +0 -1
- data/spec/spec_helper.rb +20 -18
- data/spec/spec_helper_for_sinatra.rb +22 -0
- data/spec/support/database_cleaner.rb +4 -1
- metadata +93 -141
- data/spec/models/active_record_relation_methods_spec.rb +0 -28
- data/spec/models/data_mapper_spec.rb +0 -181
- data/spec/models/default_per_page_spec.rb +0 -29
- data/spec/models/mongo_mapper_spec.rb +0 -82
- data/spec/models/mongoid_spec.rb +0 -129
- data/spec/models/scopes_spec.rb +0 -163
@@ -35,13 +35,13 @@ describe 'Kaminari::Helpers::Paginator' do
|
|
35
35
|
# end
|
36
36
|
|
37
37
|
# context '1 page in total' do
|
38
|
-
# subject { tags_with :
|
38
|
+
# subject { tags_with :total_pages => 1, :current_page => 1 }
|
39
39
|
# it { should have(0).tags }
|
40
40
|
# end
|
41
41
|
|
42
42
|
# context '10 pages in total' do
|
43
43
|
# context 'first page' do
|
44
|
-
# subject { tags_with :
|
44
|
+
# subject { tags_with :total_pages => 10, :current_page => 1 }
|
45
45
|
# it { should_not contain_tag PrevLink }
|
46
46
|
# it { should contain_tag PrevSpan }
|
47
47
|
# it { should contain_tag CurrentPage }
|
@@ -54,7 +54,7 @@ describe 'Kaminari::Helpers::Paginator' do
|
|
54
54
|
# end
|
55
55
|
|
56
56
|
# context 'second page' do
|
57
|
-
# subject { tags_with :
|
57
|
+
# subject { tags_with :total_pages => 10, :current_page => 2 }
|
58
58
|
# it { should contain_tag PrevLink }
|
59
59
|
# it { should_not contain_tag PrevSpan }
|
60
60
|
# it { should contain_tag CurrentPage }
|
@@ -67,7 +67,7 @@ describe 'Kaminari::Helpers::Paginator' do
|
|
67
67
|
# end
|
68
68
|
|
69
69
|
# context 'third page' do
|
70
|
-
# subject { tags_with :
|
70
|
+
# subject { tags_with :total_pages => 10, :current_page => 3 }
|
71
71
|
# it { should contain_tag PrevLink }
|
72
72
|
# it { should_not contain_tag PrevSpan }
|
73
73
|
# it { should contain_tag CurrentPage }
|
@@ -80,7 +80,7 @@ describe 'Kaminari::Helpers::Paginator' do
|
|
80
80
|
# end
|
81
81
|
|
82
82
|
# context 'fourth page(no truncation)' do
|
83
|
-
# subject { tags_with :
|
83
|
+
# subject { tags_with :total_pages => 10, :current_page => 4 }
|
84
84
|
# it { should contain_tag PrevLink }
|
85
85
|
# it { should_not contain_tag PrevSpan }
|
86
86
|
# it { should contain_tag CurrentPage }
|
@@ -93,7 +93,7 @@ describe 'Kaminari::Helpers::Paginator' do
|
|
93
93
|
# end
|
94
94
|
|
95
95
|
# context 'seventh page(no truncation)' do
|
96
|
-
# subject { tags_with :
|
96
|
+
# subject { tags_with :total_pages => 10, :current_page => 7 }
|
97
97
|
# it { should contain_tag PrevLink }
|
98
98
|
# it { should_not contain_tag PrevSpan }
|
99
99
|
# it { should contain_tag CurrentPage }
|
@@ -106,7 +106,7 @@ describe 'Kaminari::Helpers::Paginator' do
|
|
106
106
|
# end
|
107
107
|
|
108
108
|
# context 'eighth page' do
|
109
|
-
# subject { tags_with :
|
109
|
+
# subject { tags_with :total_pages => 10, :current_page => 8 }
|
110
110
|
# it { should contain_tag PrevLink }
|
111
111
|
# it { should_not contain_tag PrevSpan }
|
112
112
|
# it { should contain_tag CurrentPage }
|
@@ -119,7 +119,7 @@ describe 'Kaminari::Helpers::Paginator' do
|
|
119
119
|
# end
|
120
120
|
|
121
121
|
# context 'last page' do
|
122
|
-
# subject { tags_with :
|
122
|
+
# subject { tags_with :total_pages => 10, :current_page => 10 }
|
123
123
|
# it { should contain_tag PrevLink }
|
124
124
|
# it { should_not contain_tag PrevSpan }
|
125
125
|
# it { should contain_tag CurrentPage }
|
@@ -1,173 +1,169 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'spec_helper_for_sinatra'
|
3
|
-
|
4
|
-
ERB_TEMPLATE_FOR_PAGINATE = <<EOT
|
5
|
-
<div>
|
6
|
-
<ul>
|
7
|
-
<% @users.each do |user| %>
|
8
|
-
<li class="user_info"><%= user.id %></li>
|
9
|
-
<% end %>
|
10
|
-
</ul>
|
11
|
-
<%= paginate @users, @options %>
|
12
|
-
</div>
|
13
|
-
EOT
|
14
2
|
|
15
|
-
|
16
|
-
|
17
|
-
<
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
3
|
+
if defined? Sinatra
|
4
|
+
ERB_TEMPLATE_FOR_PAGINATE = <<EOT
|
5
|
+
<div>
|
6
|
+
<ul>
|
7
|
+
<% @users.each do |user| %>
|
8
|
+
<li class="user_info"><%= user.id %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
<%= paginate @users, @options %>
|
12
|
+
</div>
|
24
13
|
EOT
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
ERB_TEMPLATE_FOR_NEXT_PAGE = <<EOT
|
16
|
+
<div>
|
17
|
+
<ul>
|
18
|
+
<% @users.each do |user| %>
|
19
|
+
<li class="user_info"><%= user.id %></li>
|
20
|
+
<% end %>
|
21
|
+
</ul>
|
22
|
+
<%= link_to_next_page(@users, "Next!", {:id => 'next_page_link'}.merge(@options || {})) %>
|
23
|
+
</div>
|
24
|
+
EOT
|
30
25
|
|
31
|
-
describe '
|
26
|
+
describe 'Kaminari::Helpers::SinatraHelper' do
|
32
27
|
before do
|
33
|
-
|
34
|
-
register Kaminari::Helpers::SinatraHelpers
|
35
|
-
get '/users' do
|
36
|
-
@page = params[:page] || 1
|
37
|
-
@users = User.page(@page)
|
38
|
-
@options = {}
|
39
|
-
erb ERB_TEMPLATE_FOR_PAGINATE
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'normal paginations with Sinatra' do
|
45
|
-
before { get '/users' }
|
46
|
-
|
47
|
-
it 'should have a navigation tag' do
|
48
|
-
last_document.search('nav.pagination').should_not be_empty
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should have pagination links' do
|
52
|
-
last_document.search('.page a').should have_at_least(1).items
|
53
|
-
last_document.search('.next a').should have_at_least(1).items
|
54
|
-
last_document.search('.last a').should have_at_least(1).items
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should point to current page' do
|
58
|
-
last_document.search('.current').text.should match /1/
|
59
|
-
|
60
|
-
get '/users?page=2'
|
61
|
-
last_document.search('.current').text.should match /2/
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should load 25 users' do
|
65
|
-
last_document.search('li.user_info').should have(25).items
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should preserve params' do
|
69
|
-
get '/users?foo=bar'
|
70
|
-
last_document.search('.page a').should(be_all do |elm|
|
71
|
-
elm.attribute('href').value =~ /foo=bar/
|
72
|
-
end)
|
73
|
-
end
|
28
|
+
50.times {|i| User.create! :name => "user#{i}"}
|
74
29
|
end
|
75
30
|
|
76
|
-
|
77
|
-
|
31
|
+
describe '#paginate' do
|
32
|
+
before do
|
78
33
|
mock_app do
|
79
34
|
register Kaminari::Helpers::SinatraHelpers
|
80
35
|
get '/users' do
|
81
36
|
@page = params[:page] || 1
|
82
|
-
@users = User.page(@page)
|
37
|
+
@users = User.page(@page)
|
83
38
|
@options = {}
|
84
39
|
erb ERB_TEMPLATE_FOR_PAGINATE
|
85
40
|
end
|
86
41
|
end
|
87
|
-
|
88
|
-
get '/users'
|
89
|
-
last_document.search('.page').should have(6).items
|
90
|
-
last_document.search('.gap').should have(1).item
|
91
42
|
end
|
92
43
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
@users = User.page(@page).per(3)
|
99
|
-
@options = {:window => 10}
|
100
|
-
erb ERB_TEMPLATE_FOR_PAGINATE
|
101
|
-
end
|
44
|
+
context 'normal paginations with Sinatra' do
|
45
|
+
before { get '/users' }
|
46
|
+
|
47
|
+
it 'should have a navigation tag' do
|
48
|
+
last_document.search('nav.pagination').should_not be_empty
|
102
49
|
end
|
103
50
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
51
|
+
it 'should have pagination links' do
|
52
|
+
last_document.search('.page a').should have_at_least(1).items
|
53
|
+
last_document.search('.next a').should have_at_least(1).items
|
54
|
+
last_document.search('.last a').should have_at_least(1).items
|
55
|
+
end
|
108
56
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
get '/users'
|
113
|
-
|
114
|
-
@users = User.page(@page).per(3)
|
115
|
-
@options = {:param_name => :user_page}
|
116
|
-
erb ERB_TEMPLATE_FOR_PAGINATE
|
117
|
-
end
|
57
|
+
it 'should point to current page' do
|
58
|
+
last_document.search('.current').text.should match(/1/)
|
59
|
+
|
60
|
+
get '/users?page=2'
|
61
|
+
last_document.search('.current').text.should match(/2/)
|
118
62
|
end
|
119
63
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
64
|
+
it 'should load 25 users' do
|
65
|
+
last_document.search('li.user_info').should have(25).items
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should preserve params' do
|
69
|
+
get '/users?foo=bar'
|
70
|
+
last_document.search('.page a').should(be_all do |elm|
|
71
|
+
elm.attribute('href').value =~ /foo=bar/
|
72
|
+
end)
|
73
|
+
end
|
124
74
|
end
|
125
|
-
end
|
126
|
-
end
|
127
75
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
76
|
+
context 'optional paginations with Sinatra' do
|
77
|
+
it 'should have 5 windows with 1 gap' do
|
78
|
+
mock_app do
|
79
|
+
register Kaminari::Helpers::SinatraHelpers
|
80
|
+
get '/users' do
|
81
|
+
@page = params[:page] || 1
|
82
|
+
@users = User.page(@page).per(5)
|
83
|
+
@options = {}
|
84
|
+
erb ERB_TEMPLATE_FOR_PAGINATE
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
get '/users'
|
89
|
+
last_document.search('.page').should have(6).items
|
90
|
+
last_document.search('.gap').should have(1).item
|
136
91
|
end
|
137
92
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
93
|
+
it 'should controll the inner window size' do
|
94
|
+
mock_app do
|
95
|
+
register Kaminari::Helpers::SinatraHelpers
|
96
|
+
get '/users' do
|
97
|
+
@page = params[:page] || 1
|
98
|
+
@users = User.page(@page).per(3)
|
99
|
+
@options = {:window => 10}
|
100
|
+
erb ERB_TEMPLATE_FOR_PAGINATE
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
get '/users'
|
105
|
+
last_document.search('.page').should have(12).items
|
106
|
+
last_document.search('.gap').should have(1).item
|
143
107
|
end
|
144
|
-
end
|
145
|
-
end
|
146
108
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
109
|
+
it 'should specify a page param name' do
|
110
|
+
mock_app do
|
111
|
+
register Kaminari::Helpers::SinatraHelpers
|
112
|
+
get '/users' do
|
113
|
+
@page = params[:page] || 1
|
114
|
+
@users = User.page(@page).per(3)
|
115
|
+
@options = {:param_name => :user_page}
|
116
|
+
erb ERB_TEMPLATE_FOR_PAGINATE
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
get '/users'
|
121
|
+
last_document.search('.page a').should(be_all do |elm|
|
122
|
+
elm.attribute('href').value =~ /user_page=\d+/
|
123
|
+
end)
|
124
|
+
end
|
152
125
|
end
|
153
126
|
end
|
154
127
|
|
155
|
-
|
128
|
+
describe '#link_to_next_page' do
|
156
129
|
before do
|
157
|
-
|
158
|
-
|
130
|
+
mock_app do
|
131
|
+
register Kaminari::Helpers::SinatraHelpers
|
132
|
+
get '/users' do
|
133
|
+
@page = params[:page] || 1
|
134
|
+
@users = User.page(@page)
|
135
|
+
erb ERB_TEMPLATE_FOR_NEXT_PAGE
|
136
|
+
end
|
137
|
+
|
138
|
+
get '/users_placeholder' do
|
139
|
+
@page = params[:page] || 1
|
140
|
+
@options = {:placeholder => %{<span id='no_next_page'>No Next Page</span>}}
|
141
|
+
@users = User.page(@page)
|
142
|
+
erb ERB_TEMPLATE_FOR_NEXT_PAGE
|
143
|
+
end
|
144
|
+
end
|
159
145
|
end
|
160
146
|
|
161
|
-
|
162
|
-
|
163
|
-
|
147
|
+
context 'having more page' do
|
148
|
+
it 'should have a more page link' do
|
149
|
+
get '/users'
|
150
|
+
last_document.search('a#next_page_link').should be_present
|
151
|
+
last_document.search('a#next_page_link').text.should match(/Next!/)
|
152
|
+
end
|
164
153
|
end
|
165
154
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
155
|
+
context 'the last page' do
|
156
|
+
it 'should not have a more page link' do
|
157
|
+
get '/users?page=2'
|
158
|
+
last_document.search('a#next_page_link').should be_empty
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should have a no more page notation using placeholder' do
|
162
|
+
get '/users_placeholder?page=2'
|
163
|
+
last_document.search('a#next_page_link').should be_empty
|
164
|
+
last_document.search('span#no_next_page').should be_present
|
165
|
+
last_document.search('span#no_next_page').text.should match(/No Next Page/)
|
166
|
+
end
|
171
167
|
end
|
172
168
|
end
|
173
169
|
end
|
data/spec/helpers/tags_spec.rb
CHANGED
@@ -28,11 +28,11 @@ describe 'Kaminari::Helpers' do
|
|
28
28
|
|
29
29
|
describe '#last?' do
|
30
30
|
context 'current_page == page' do
|
31
|
-
subject { Paginator::PageProxy.new({:
|
31
|
+
subject { Paginator::PageProxy.new({:total_pages => 39}, 39, nil) }
|
32
32
|
its(:last?) { should be_true }
|
33
33
|
end
|
34
34
|
context 'current_page != page' do
|
35
|
-
subject { Paginator::PageProxy.new({:
|
35
|
+
subject { Paginator::PageProxy.new({:total_pages => 39}, 38, nil) }
|
36
36
|
its(:last?) { should_not be_true }
|
37
37
|
end
|
38
38
|
end
|
@@ -75,16 +75,16 @@ describe 'Kaminari::Helpers' do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
describe '#right_outer?' do
|
78
|
-
context '
|
79
|
-
subject { Paginator::PageProxy.new({:
|
78
|
+
context 'total_pages - page > right' do
|
79
|
+
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 6, nil) }
|
80
80
|
its(:right_outer?) { should_not be_true }
|
81
81
|
end
|
82
|
-
context '
|
83
|
-
subject { Paginator::PageProxy.new({:
|
82
|
+
context 'total_pages - page == right' do
|
83
|
+
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 7, nil) }
|
84
84
|
its(:right_outer?) { should_not be_true }
|
85
85
|
end
|
86
|
-
context '
|
87
|
-
subject { Paginator::PageProxy.new({:
|
86
|
+
context 'total_pages - page < right' do
|
87
|
+
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 8, nil) }
|
88
88
|
its(:right_outer?) { should be_true }
|
89
89
|
end
|
90
90
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
if defined? ActiveRecord
|
4
|
+
describe Kaminari::ActiveRecordRelationMethods do
|
5
|
+
describe '#total_count' do
|
6
|
+
before do
|
7
|
+
@author = User.create! :name => 'author'
|
8
|
+
@author2 = User.create! :name => 'author2'
|
9
|
+
@author3 = User.create! :name => 'author3'
|
10
|
+
@books = 2.times.map {|i| @author.books_authored.create!(:title => "title%03d" % i) }
|
11
|
+
@books2 = 3.times.map {|i| @author2.books_authored.create!(:title => "title%03d" % i) }
|
12
|
+
@books3 = 4.times.map {|i| @author3.books_authored.create!(:title => "subject%03d" % i) }
|
13
|
+
@readers = 4.times.map { User.create! :name => 'reader' }
|
14
|
+
@books.each {|book| book.readers << @readers }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when the scope includes an order which references a generated column" do
|
18
|
+
it "should successfully count the results" do
|
19
|
+
@author.readers.by_read_count.page(1).total_count.should == @readers.size
|
20
|
+
end
|
21
|
+
end
|
22
|
+
context "when the scope use conditions on includes" do
|
23
|
+
it "should keep includes and successfully count the results" do
|
24
|
+
# Only @author and @author2 have books titled with the title00x partern
|
25
|
+
User.includes(:books_authored).where("books.title LIKE 'title00%'").page(1).total_count.should == 2
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
if defined? ActiveRecord
|
4
|
+
|
5
|
+
describe 'default per_page' do
|
6
|
+
describe 'AR::Base' do
|
7
|
+
subject { ActiveRecord::Base }
|
8
|
+
it { should_not respond_to :paginates_per }
|
9
|
+
end
|
10
|
+
|
11
|
+
subject { User.page 0 }
|
12
|
+
|
13
|
+
context 'by default' do
|
14
|
+
its(:limit_value) { should == 25 }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when explicitly set via paginates_per' do
|
18
|
+
before { User.paginates_per 1326 }
|
19
|
+
its(:limit_value) { should == 1326 }
|
20
|
+
after { User.paginates_per nil }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "default per_page value's independency per model" do
|
24
|
+
context "when User's default per_page was changed" do
|
25
|
+
before { User.paginates_per 1326 }
|
26
|
+
subject { Book.page 0 }
|
27
|
+
its(:limit_value) { should == 25 }
|
28
|
+
after { User.paginates_per nil }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|