kaminari 0.17.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +19 -0
- data/.gitignore +1 -1
- data/.travis.yml +79 -45
- data/CHANGELOG.md +636 -0
- data/CONTRIBUTING.md +22 -0
- data/Gemfile +2 -0
- data/README.md +573 -0
- data/Rakefile +25 -25
- data/gemfiles/active_record_41.gemfile +10 -7
- data/gemfiles/active_record_42.gemfile +10 -7
- data/gemfiles/active_record_50.gemfile +24 -0
- data/gemfiles/active_record_51.gemfile +24 -0
- data/gemfiles/active_record_52.gemfile +24 -0
- data/gemfiles/active_record_60.gemfile +26 -0
- data/gemfiles/active_record_edge.gemfile +15 -12
- data/kaminari.gemspec +23 -27
- data/lib/kaminari/version.rb +3 -1
- data/lib/kaminari.rb +4 -38
- data/misc/bug_report_template.rb +57 -0
- metadata +48 -186
- data/.gemtest +0 -0
- data/.rspec +0 -2
- data/CHANGELOG.rdoc +0 -480
- data/README.rdoc +0 -336
- data/app/views/kaminari/_first_page.html.erb +0 -11
- data/app/views/kaminari/_first_page.html.haml +0 -9
- data/app/views/kaminari/_first_page.html.slim +0 -10
- data/app/views/kaminari/_gap.html.erb +0 -8
- data/app/views/kaminari/_gap.html.haml +0 -8
- data/app/views/kaminari/_gap.html.slim +0 -9
- data/app/views/kaminari/_last_page.html.erb +0 -11
- data/app/views/kaminari/_last_page.html.haml +0 -9
- data/app/views/kaminari/_last_page.html.slim +0 -10
- data/app/views/kaminari/_next_page.html.erb +0 -11
- data/app/views/kaminari/_next_page.html.haml +0 -9
- data/app/views/kaminari/_next_page.html.slim +0 -10
- data/app/views/kaminari/_page.html.erb +0 -12
- data/app/views/kaminari/_page.html.haml +0 -10
- data/app/views/kaminari/_page.html.slim +0 -11
- data/app/views/kaminari/_paginator.html.erb +0 -23
- data/app/views/kaminari/_paginator.html.haml +0 -18
- data/app/views/kaminari/_paginator.html.slim +0 -19
- data/app/views/kaminari/_prev_page.html.erb +0 -11
- data/app/views/kaminari/_prev_page.html.haml +0 -9
- data/app/views/kaminari/_prev_page.html.slim +0 -10
- data/config/locales/kaminari.yml +0 -19
- data/gemfiles/active_record_30.gemfile +0 -28
- data/gemfiles/active_record_31.gemfile +0 -26
- data/gemfiles/active_record_32.gemfile +0 -25
- data/gemfiles/active_record_40.gemfile +0 -26
- data/gemfiles/data_mapper_12.gemfile +0 -32
- data/gemfiles/mongo_mapper.gemfile +0 -25
- data/gemfiles/mongoid_30.gemfile +0 -22
- data/gemfiles/mongoid_31.gemfile +0 -21
- data/gemfiles/mongoid_40.gemfile +0 -19
- data/gemfiles/mongoid_50.gemfile +0 -23
- data/gemfiles/sinatra_13.gemfile +0 -36
- data/gemfiles/sinatra_14.gemfile +0 -33
- data/lib/generators/kaminari/config_generator.rb +0 -16
- data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
- data/lib/generators/kaminari/views_generator.rb +0 -119
- data/lib/kaminari/config.rb +0 -51
- data/lib/kaminari/engine.rb +0 -4
- data/lib/kaminari/grape.rb +0 -4
- data/lib/kaminari/helpers/action_view_extension.rb +0 -132
- data/lib/kaminari/helpers/paginator.rb +0 -195
- data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
- data/lib/kaminari/helpers/tags.rb +0 -108
- data/lib/kaminari/hooks.rb +0 -53
- data/lib/kaminari/models/active_record_extension.rb +0 -22
- data/lib/kaminari/models/active_record_model_extension.rb +0 -22
- data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
- data/lib/kaminari/models/array_extension.rb +0 -66
- data/lib/kaminari/models/configuration_methods.rb +0 -48
- data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
- data/lib/kaminari/models/data_mapper_extension.rb +0 -51
- data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
- data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
- data/lib/kaminari/models/mongoid_extension.rb +0 -26
- data/lib/kaminari/models/page_scope_methods.rb +0 -73
- data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
- data/lib/kaminari/railtie.rb +0 -7
- data/lib/kaminari/sinatra.rb +0 -7
- data/spec/config/config_spec.rb +0 -91
- data/spec/fake_app/active_record/config.rb +0 -3
- data/spec/fake_app/active_record/models.rb +0 -65
- data/spec/fake_app/data_mapper/config.rb +0 -1
- data/spec/fake_app/data_mapper/models.rb +0 -27
- data/spec/fake_app/mongo_mapper/config.rb +0 -2
- data/spec/fake_app/mongo_mapper/models.rb +0 -9
- data/spec/fake_app/mongoid/config.rb +0 -20
- data/spec/fake_app/mongoid/models.rb +0 -38
- data/spec/fake_app/rails_app.rb +0 -56
- data/spec/fake_app/sinatra_app.rb +0 -22
- data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
- data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
- data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
- data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
- data/spec/fake_gem.rb +0 -20
- data/spec/generators/views_generator_spec.rb +0 -18
- data/spec/helpers/action_view_extension_spec.rb +0 -318
- data/spec/helpers/helpers_spec.rb +0 -144
- data/spec/helpers/sinatra_helpers_spec.rb +0 -223
- data/spec/helpers/tags_spec.rb +0 -140
- data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
- data/spec/models/active_record/inherited_spec.rb +0 -9
- data/spec/models/active_record/scopes_spec.rb +0 -265
- data/spec/models/array_spec.rb +0 -172
- data/spec/models/configuration_methods_spec.rb +0 -125
- data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
- data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
- data/spec/models/mongoid/mongoid_spec.rb +0 -228
- data/spec/requests/users_spec.rb +0 -53
- data/spec/spec_helper.rb +0 -34
- data/spec/spec_helper_for_sinatra.rb +0 -34
- data/spec/support/database_cleaner.rb +0 -19
- data/spec/support/matchers.rb +0 -52
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
include Kaminari::Helpers
|
3
|
-
|
4
|
-
describe 'Kaminari::Helpers::Paginator' do
|
5
|
-
let :template do
|
6
|
-
stub(r = Object.new) do
|
7
|
-
render.with_any_args
|
8
|
-
params { {} }
|
9
|
-
options { {} }
|
10
|
-
url_for {|h| "/foo?page=#{h[:page]}"}
|
11
|
-
link_to { "<a href='#'>link</a>" }
|
12
|
-
end
|
13
|
-
r
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "view helper methods delegated to template" do
|
17
|
-
before do
|
18
|
-
@paginator = Paginator.new(template, :params => {})
|
19
|
-
end
|
20
|
-
subject { @paginator.link_to("link", "#") }
|
21
|
-
it { should == "<a href='#'>link</a>" }
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#params' do
|
25
|
-
before do
|
26
|
-
@paginator = Paginator.new(template, :params => {:controller => 'foo', :action => 'bar'})
|
27
|
-
end
|
28
|
-
subject { @paginator.page_tag(template).instance_variable_get('@params') }
|
29
|
-
it { should == {:controller => 'foo', :action => 'bar'} }
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#param_name' do
|
33
|
-
before do
|
34
|
-
@paginator = Paginator.new(template, :param_name => :pagina)
|
35
|
-
end
|
36
|
-
subject { @paginator.page_tag(template).instance_variable_get('@param_name') }
|
37
|
-
it { should == :pagina }
|
38
|
-
end
|
39
|
-
|
40
|
-
#TODO test somehow...
|
41
|
-
# describe '#tagify_links' do
|
42
|
-
# def tags_with(options)
|
43
|
-
# PaginationRenderer.new(template, options).tagify_links
|
44
|
-
# end
|
45
|
-
|
46
|
-
# context '1 page in total' do
|
47
|
-
# subject { tags_with :total_pages => 1, :current_page => 1 }
|
48
|
-
# it { should have(0).tags }
|
49
|
-
# end
|
50
|
-
|
51
|
-
# context '10 pages in total' do
|
52
|
-
# context 'first page' do
|
53
|
-
# subject { tags_with :total_pages => 10, :current_page => 1 }
|
54
|
-
# it { should_not contain_tag PrevLink }
|
55
|
-
# it { should contain_tag PrevSpan }
|
56
|
-
# it { should contain_tag CurrentPage }
|
57
|
-
# it { should_not contain_tag FirstPageLink }
|
58
|
-
# it { should contain_tag LastPageLink }
|
59
|
-
# it { should contain_tag PageLink }
|
60
|
-
# it { should contain_tag NextLink }
|
61
|
-
# it { should_not contain_tag NextSpan }
|
62
|
-
# it { should contain_tag TruncatedSpan }
|
63
|
-
# end
|
64
|
-
|
65
|
-
# context 'second page' do
|
66
|
-
# subject { tags_with :total_pages => 10, :current_page => 2 }
|
67
|
-
# it { should contain_tag PrevLink }
|
68
|
-
# it { should_not contain_tag PrevSpan }
|
69
|
-
# it { should contain_tag CurrentPage }
|
70
|
-
# it { should contain_tag FirstPageLink }
|
71
|
-
# it { should contain_tag LastPageLink }
|
72
|
-
# it { should contain_tag PageLink }
|
73
|
-
# it { should contain_tag NextLink }
|
74
|
-
# it { should_not contain_tag NextSpan }
|
75
|
-
# it { should contain_tag TruncatedSpan }
|
76
|
-
# end
|
77
|
-
|
78
|
-
# context 'third page' do
|
79
|
-
# subject { tags_with :total_pages => 10, :current_page => 3 }
|
80
|
-
# it { should contain_tag PrevLink }
|
81
|
-
# it { should_not contain_tag PrevSpan }
|
82
|
-
# it { should contain_tag CurrentPage }
|
83
|
-
# it { should contain_tag FirstPageLink }
|
84
|
-
# it { should contain_tag LastPageLink }
|
85
|
-
# it { should contain_tag PageLink }
|
86
|
-
# it { should contain_tag NextLink }
|
87
|
-
# it { should_not contain_tag NextSpan }
|
88
|
-
# it { should contain_tag TruncatedSpan }
|
89
|
-
# end
|
90
|
-
|
91
|
-
# context 'fourth page(no truncation)' do
|
92
|
-
# subject { tags_with :total_pages => 10, :current_page => 4 }
|
93
|
-
# it { should contain_tag PrevLink }
|
94
|
-
# it { should_not contain_tag PrevSpan }
|
95
|
-
# it { should contain_tag CurrentPage }
|
96
|
-
# it { should contain_tag FirstPageLink }
|
97
|
-
# it { should contain_tag LastPageLink }
|
98
|
-
# it { should contain_tag PageLink }
|
99
|
-
# it { should contain_tag NextLink }
|
100
|
-
# it { should_not contain_tag NextSpan }
|
101
|
-
# it { should_not contain_tag TruncatedSpan }
|
102
|
-
# end
|
103
|
-
|
104
|
-
# context 'seventh page(no truncation)' do
|
105
|
-
# subject { tags_with :total_pages => 10, :current_page => 7 }
|
106
|
-
# it { should contain_tag PrevLink }
|
107
|
-
# it { should_not contain_tag PrevSpan }
|
108
|
-
# it { should contain_tag CurrentPage }
|
109
|
-
# it { should contain_tag FirstPageLink }
|
110
|
-
# it { should contain_tag LastPageLink }
|
111
|
-
# it { should contain_tag PageLink }
|
112
|
-
# it { should contain_tag NextLink }
|
113
|
-
# it { should_not contain_tag NextSpan }
|
114
|
-
# it { should_not contain_tag TruncatedSpan }
|
115
|
-
# end
|
116
|
-
|
117
|
-
# context 'eighth page' do
|
118
|
-
# subject { tags_with :total_pages => 10, :current_page => 8 }
|
119
|
-
# it { should contain_tag PrevLink }
|
120
|
-
# it { should_not contain_tag PrevSpan }
|
121
|
-
# it { should contain_tag CurrentPage }
|
122
|
-
# it { should contain_tag FirstPageLink }
|
123
|
-
# it { should contain_tag LastPageLink }
|
124
|
-
# it { should contain_tag PageLink }
|
125
|
-
# it { should contain_tag NextLink }
|
126
|
-
# it { should_not contain_tag NextSpan }
|
127
|
-
# it { should contain_tag TruncatedSpan }
|
128
|
-
# end
|
129
|
-
|
130
|
-
# context 'last page' do
|
131
|
-
# subject { tags_with :total_pages => 10, :current_page => 10 }
|
132
|
-
# it { should contain_tag PrevLink }
|
133
|
-
# it { should_not contain_tag PrevSpan }
|
134
|
-
# it { should contain_tag CurrentPage }
|
135
|
-
# it { should contain_tag FirstPageLink }
|
136
|
-
# it { should_not contain_tag LastPageLink }
|
137
|
-
# it { should contain_tag PageLink }
|
138
|
-
# it { should_not contain_tag NextLink }
|
139
|
-
# it { should contain_tag NextSpan }
|
140
|
-
# it { should contain_tag TruncatedSpan }
|
141
|
-
# end
|
142
|
-
# end
|
143
|
-
# end
|
144
|
-
end
|
@@ -1,223 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
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>
|
13
|
-
EOT
|
14
|
-
|
15
|
-
ERB_TEMPLATE_FOR_PREVIOUS_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_previous_page(@users, "Previous!", {:id => 'previous_page_link'}.merge(@options || {})) %>
|
23
|
-
</div>
|
24
|
-
EOT
|
25
|
-
|
26
|
-
ERB_TEMPLATE_FOR_NEXT_PAGE = <<EOT
|
27
|
-
<div>
|
28
|
-
<ul>
|
29
|
-
<% @users.each do |user| %>
|
30
|
-
<li class="user_info"><%= user.id %></li>
|
31
|
-
<% end %>
|
32
|
-
</ul>
|
33
|
-
<%= link_to_next_page(@users, "Next!", {:id => 'next_page_link'}.merge(@options || {})) %>
|
34
|
-
</div>
|
35
|
-
EOT
|
36
|
-
|
37
|
-
describe 'Kaminari::Helpers::SinatraHelper' do
|
38
|
-
before do
|
39
|
-
50.times {|i| User.create! :name => "user#{i}"}
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#paginate' do
|
43
|
-
before do
|
44
|
-
mock_app do
|
45
|
-
register Kaminari::Helpers::SinatraHelpers
|
46
|
-
get '/users' do
|
47
|
-
@page = params[:page] || 1
|
48
|
-
@users = User.page(@page)
|
49
|
-
@options = {}
|
50
|
-
erb ERB_TEMPLATE_FOR_PAGINATE
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'normal paginations with Sinatra' do
|
56
|
-
before { get '/users' }
|
57
|
-
|
58
|
-
it 'should have a navigation tag' do
|
59
|
-
last_document.search('nav.pagination').should_not be_empty
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should have pagination links' do
|
63
|
-
last_document.search('.page a').should have_at_least(1).items
|
64
|
-
last_document.search('.next a').should have_at_least(1).items
|
65
|
-
last_document.search('.last a').should have_at_least(1).items
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should point to current page' do
|
69
|
-
last_document.search('.current').text.should match(/1/)
|
70
|
-
|
71
|
-
get '/users?page=2'
|
72
|
-
last_document.search('.current').text.should match(/2/)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should load 25 users' do
|
76
|
-
last_document.search('li.user_info').should have(25).items
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'should preserve params' do
|
80
|
-
get '/users?foo=bar'
|
81
|
-
last_document.search('.page a').should(be_all do |elm|
|
82
|
-
elm.attribute('href').value =~ /foo=bar/
|
83
|
-
end)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'optional paginations with Sinatra' do
|
88
|
-
it 'should have 5 windows with 1 gap' do
|
89
|
-
mock_app do
|
90
|
-
register Kaminari::Helpers::SinatraHelpers
|
91
|
-
get '/users' do
|
92
|
-
@page = params[:page] || 1
|
93
|
-
@users = User.page(@page).per(5)
|
94
|
-
@options = {}
|
95
|
-
erb ERB_TEMPLATE_FOR_PAGINATE
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
get '/users'
|
100
|
-
last_document.search('.page').should have(6).items
|
101
|
-
last_document.search('.gap').should have(1).item
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'should controll the inner window size' do
|
105
|
-
mock_app do
|
106
|
-
register Kaminari::Helpers::SinatraHelpers
|
107
|
-
get '/users' do
|
108
|
-
@page = params[:page] || 1
|
109
|
-
@users = User.page(@page).per(3)
|
110
|
-
@options = {:window => 10}
|
111
|
-
erb ERB_TEMPLATE_FOR_PAGINATE
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
get '/users'
|
116
|
-
last_document.search('.page').should have(12).items
|
117
|
-
last_document.search('.gap').should have(1).item
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'should specify a page param name' do
|
121
|
-
mock_app do
|
122
|
-
register Kaminari::Helpers::SinatraHelpers
|
123
|
-
get '/users' do
|
124
|
-
@page = params[:page] || 1
|
125
|
-
@users = User.page(@page).per(3)
|
126
|
-
@options = {:param_name => :user_page}
|
127
|
-
erb ERB_TEMPLATE_FOR_PAGINATE
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
get '/users'
|
132
|
-
last_document.search('.page a').should(be_all do |elm|
|
133
|
-
elm.attribute('href').value =~ /user_page=\d+/
|
134
|
-
end)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe '#link_to_previous_page' do
|
140
|
-
before do
|
141
|
-
mock_app do
|
142
|
-
register Kaminari::Helpers::SinatraHelpers
|
143
|
-
get '/users' do
|
144
|
-
@page = params[:page] || 2
|
145
|
-
@users = User.page(@page)
|
146
|
-
erb ERB_TEMPLATE_FOR_PREVIOUS_PAGE
|
147
|
-
end
|
148
|
-
|
149
|
-
get '/users_placeholder' do
|
150
|
-
@page = params[:page] || 2
|
151
|
-
@options = {:placeholder => %{<span id='no_previous_page'>No Previous Page</span>}}
|
152
|
-
@users = User.page(@page)
|
153
|
-
erb ERB_TEMPLATE_FOR_PREVIOUS_PAGE
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
context 'having more page' do
|
159
|
-
it 'should have a more page link' do
|
160
|
-
get '/users'
|
161
|
-
last_document.search('a#previous_page_link').should be_present
|
162
|
-
last_document.search('a#previous_page_link').text.should match(/Previous!/)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context 'the first page' do
|
167
|
-
it 'should not have a more page link' do
|
168
|
-
get '/users?page=1'
|
169
|
-
last_document.search('a#previous_page_link').should be_empty
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'should have a no more page notation using placeholder' do
|
173
|
-
get '/users_placeholder?page=1'
|
174
|
-
last_document.search('a#previous_page_link').should be_empty
|
175
|
-
last_document.search('span#no_previous_page').should be_present
|
176
|
-
last_document.search('span#no_previous_page').text.should match(/No Previous Page/)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
describe '#link_to_next_page' do
|
182
|
-
before do
|
183
|
-
mock_app do
|
184
|
-
register Kaminari::Helpers::SinatraHelpers
|
185
|
-
get '/users' do
|
186
|
-
@page = params[:page] || 1
|
187
|
-
@users = User.page(@page)
|
188
|
-
erb ERB_TEMPLATE_FOR_NEXT_PAGE
|
189
|
-
end
|
190
|
-
|
191
|
-
get '/users_placeholder' do
|
192
|
-
@page = params[:page] || 1
|
193
|
-
@options = {:placeholder => %{<span id='no_next_page'>No Next Page</span>}}
|
194
|
-
@users = User.page(@page)
|
195
|
-
erb ERB_TEMPLATE_FOR_NEXT_PAGE
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
context 'having more page' do
|
201
|
-
it 'should have a more page link' do
|
202
|
-
get '/users'
|
203
|
-
last_document.search('a#next_page_link').should be_present
|
204
|
-
last_document.search('a#next_page_link').text.should match(/Next!/)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
context 'the last page' do
|
209
|
-
it 'should not have a more page link' do
|
210
|
-
get '/users?page=2'
|
211
|
-
last_document.search('a#next_page_link').should be_empty
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'should have a no more page notation using placeholder' do
|
215
|
-
get '/users_placeholder?page=2'
|
216
|
-
last_document.search('a#next_page_link').should be_empty
|
217
|
-
last_document.search('span#no_next_page').should be_present
|
218
|
-
last_document.search('span#no_next_page').text.should match(/No Next Page/)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
data/spec/helpers/tags_spec.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
include Kaminari::Helpers
|
3
|
-
|
4
|
-
describe 'Kaminari::Helpers' do
|
5
|
-
describe 'Paginator' do
|
6
|
-
describe 'Paginator::PageProxy' do
|
7
|
-
describe '#current?' do
|
8
|
-
context 'current_page == page' do
|
9
|
-
subject { Paginator::PageProxy.new({:current_page => 26}, 26, nil) }
|
10
|
-
its(:current?) { should be_true }
|
11
|
-
end
|
12
|
-
context 'current_page != page' do
|
13
|
-
subject { Paginator::PageProxy.new({:current_page => 13}, 26, nil) }
|
14
|
-
its(:current?) { should_not be_true }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#first?' do
|
19
|
-
context 'page == 1' do
|
20
|
-
subject { Paginator::PageProxy.new({:current_page => 26}, 1, nil) }
|
21
|
-
its(:first?) { should be_true }
|
22
|
-
end
|
23
|
-
context 'page != 1' do
|
24
|
-
subject { Paginator::PageProxy.new({:current_page => 13}, 2, nil) }
|
25
|
-
its(:first?) { should_not be_true }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '#last?' do
|
30
|
-
context 'current_page == page' do
|
31
|
-
subject { Paginator::PageProxy.new({:total_pages => 39}, 39, nil) }
|
32
|
-
its(:last?) { should be_true }
|
33
|
-
end
|
34
|
-
context 'current_page != page' do
|
35
|
-
subject { Paginator::PageProxy.new({:total_pages => 39}, 38, nil) }
|
36
|
-
its(:last?) { should_not be_true }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#next?' do
|
41
|
-
context 'page == current_page + 1' do
|
42
|
-
subject { Paginator::PageProxy.new({:current_page => 52}, 53, nil) }
|
43
|
-
its(:next?) { should be_true }
|
44
|
-
end
|
45
|
-
context 'page != current_page + 1' do
|
46
|
-
subject { Paginator::PageProxy.new({:current_page => 52}, 77, nil) }
|
47
|
-
its(:next?) { should_not be_true }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe '#prev?' do
|
52
|
-
context 'page == current_page - 1' do
|
53
|
-
subject { Paginator::PageProxy.new({:current_page => 77}, 76, nil) }
|
54
|
-
its(:prev?) { should be_true }
|
55
|
-
end
|
56
|
-
context 'page != current_page + 1' do
|
57
|
-
subject { Paginator::PageProxy.new({:current_page => 77}, 80, nil) }
|
58
|
-
its(:prev?) { should_not be_true }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe '#left_outer?' do
|
63
|
-
context 'current_page == left' do
|
64
|
-
subject { Paginator::PageProxy.new({:left => 3}, 3, nil) }
|
65
|
-
its(:left_outer?) { should be_true }
|
66
|
-
end
|
67
|
-
context 'current_page == left + 1' do
|
68
|
-
subject { Paginator::PageProxy.new({:left => 3}, 4, nil) }
|
69
|
-
its(:left_outer?) { should_not be_true }
|
70
|
-
end
|
71
|
-
context 'current_page == left + 2' do
|
72
|
-
subject { Paginator::PageProxy.new({:left => 3}, 5, nil) }
|
73
|
-
its(:left_outer?) { should_not be_true }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe '#right_outer?' do
|
78
|
-
context 'total_pages - page > right' do
|
79
|
-
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 6, nil) }
|
80
|
-
its(:right_outer?) { should_not be_true }
|
81
|
-
end
|
82
|
-
context 'total_pages - page == right' do
|
83
|
-
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 7, nil) }
|
84
|
-
its(:right_outer?) { should_not be_true }
|
85
|
-
end
|
86
|
-
context 'total_pages - page < right' do
|
87
|
-
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 8, nil) }
|
88
|
-
its(:right_outer?) { should be_true }
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe '#inside_window?' do
|
93
|
-
context 'page > current_page' do
|
94
|
-
context 'page - current_page > window' do
|
95
|
-
subject { Paginator::PageProxy.new({:current_page => 4, :window => 5}, 10, nil) }
|
96
|
-
its(:inside_window?) { should_not be_true }
|
97
|
-
end
|
98
|
-
context 'page - current_page == window' do
|
99
|
-
subject { Paginator::PageProxy.new({:current_page => 4, :window => 6}, 10, nil) }
|
100
|
-
its(:inside_window?) { should be_true }
|
101
|
-
end
|
102
|
-
context 'page - current_page < window' do
|
103
|
-
subject { Paginator::PageProxy.new({:current_page => 4, :window => 7}, 10, nil) }
|
104
|
-
its(:inside_window?) { should be_true }
|
105
|
-
end
|
106
|
-
end
|
107
|
-
context 'current_page > page' do
|
108
|
-
context 'current_page - page > window' do
|
109
|
-
subject { Paginator::PageProxy.new({:current_page => 15, :window => 4}, 10, nil) }
|
110
|
-
its(:inside_window?) { should_not be_true }
|
111
|
-
end
|
112
|
-
context 'current_page - page == window' do
|
113
|
-
subject { Paginator::PageProxy.new({:current_page => 15, :window => 5}, 10, nil) }
|
114
|
-
its(:inside_window?) { should be_true }
|
115
|
-
end
|
116
|
-
context 'current_page - page < window' do
|
117
|
-
subject { Paginator::PageProxy.new({:current_page => 15, :window => 6}, 10, nil) }
|
118
|
-
its(:inside_window?) { should be_true }
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
describe '#was_truncated?' do
|
123
|
-
before do
|
124
|
-
stub(@template = Object.new) do
|
125
|
-
options { {} }
|
126
|
-
params { {} }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
context 'last.is_a? Gap' do
|
130
|
-
subject { Paginator::PageProxy.new({}, 10, Gap.new(@template)) }
|
131
|
-
its(:was_truncated?) { should be_true }
|
132
|
-
end
|
133
|
-
context 'last.is not a Gap' do
|
134
|
-
subject { Paginator::PageProxy.new({}, 10, Page.new(@template)) }
|
135
|
-
its(:was_truncated?) { should_not be_true }
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|