mislav-will_paginate 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +62 -0
- data/LICENSE +18 -0
- data/README.rdoc +135 -0
- data/Rakefile +110 -0
- data/examples/apple-circle.gif +0 -0
- data/examples/index.haml +69 -0
- data/examples/index.html +92 -0
- data/examples/pagination.css +90 -0
- data/examples/pagination.sass +91 -0
- data/init.rb +1 -0
- data/lib/will_paginate.rb +86 -0
- data/lib/will_paginate/array.rb +16 -0
- data/lib/will_paginate/collection.rb +145 -0
- data/lib/will_paginate/core_ext.rb +32 -0
- data/lib/will_paginate/finder.rb +239 -0
- data/lib/will_paginate/named_scope.rb +132 -0
- data/lib/will_paginate/named_scope_patch.rb +39 -0
- data/lib/will_paginate/version.rb +9 -0
- data/lib/will_paginate/view_helpers.rb +341 -0
- data/test/boot.rb +21 -0
- data/test/collection_test.rb +140 -0
- data/test/console +8 -0
- data/test/database.yml +22 -0
- data/test/finder_test.rb +416 -0
- data/test/fixtures/admin.rb +3 -0
- data/test/fixtures/developer.rb +13 -0
- data/test/fixtures/developers_projects.yml +13 -0
- data/test/fixtures/project.rb +15 -0
- data/test/fixtures/projects.yml +6 -0
- data/test/fixtures/replies.yml +29 -0
- data/test/fixtures/reply.rb +7 -0
- data/test/fixtures/schema.rb +38 -0
- data/test/fixtures/topic.rb +6 -0
- data/test/fixtures/topics.yml +30 -0
- data/test/fixtures/user.rb +2 -0
- data/test/fixtures/users.yml +35 -0
- data/test/helper.rb +37 -0
- data/test/lib/activerecord_test_case.rb +36 -0
- data/test/lib/activerecord_test_connector.rb +69 -0
- data/test/lib/load_fixtures.rb +11 -0
- data/test/lib/view_test_process.rb +157 -0
- data/test/view_test.rb +278 -0
- metadata +130 -0
data/test/view_test.rb
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'lib/view_test_process'
|
3
|
+
|
4
|
+
class ViewTest < WillPaginate::ViewTestCase
|
5
|
+
|
6
|
+
## basic pagination ##
|
7
|
+
|
8
|
+
def test_will_paginate
|
9
|
+
paginate do |pagination|
|
10
|
+
assert_select 'a[href]', 3 do |elements|
|
11
|
+
validate_page_numbers [2,3,2], elements
|
12
|
+
assert_select elements.last, ':last-child', "Next »"
|
13
|
+
end
|
14
|
+
assert_select 'span', 2
|
15
|
+
assert_select 'span.disabled:first-child', '« Previous'
|
16
|
+
assert_select 'span.current', '1'
|
17
|
+
assert_equal '« Previous 1 2 3 Next »', pagination.first.inner_text
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_no_pagination_when_page_count_is_one
|
22
|
+
paginate :per_page => 30
|
23
|
+
assert_equal '', @html_result
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_will_paginate_with_options
|
27
|
+
paginate({ :page => 2 },
|
28
|
+
:class => 'will_paginate', :prev_label => 'Prev', :next_label => 'Next') do
|
29
|
+
assert_select 'a[href]', 4 do |elements|
|
30
|
+
validate_page_numbers [1,1,3,3], elements
|
31
|
+
# test rel attribute values:
|
32
|
+
assert_select elements[1], 'a', '1' do |link|
|
33
|
+
assert_equal 'prev start', link.first['rel']
|
34
|
+
end
|
35
|
+
assert_select elements.first, 'a', "Prev" do |link|
|
36
|
+
assert_equal 'prev start', link.first['rel']
|
37
|
+
end
|
38
|
+
assert_select elements.last, 'a', "Next" do |link|
|
39
|
+
assert_equal 'next', link.first['rel']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
assert_select 'span.current', '2'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_prev_next_links_have_classnames
|
47
|
+
paginate do |pagination|
|
48
|
+
assert_select 'span.disabled.prev_page:first-child'
|
49
|
+
assert_select 'a.next_page[href]:last-child'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_full_output
|
54
|
+
paginate
|
55
|
+
expected = <<-HTML
|
56
|
+
<div class="pagination"><span class="disabled prev_page">« Previous</span>
|
57
|
+
<span class="current">1</span>
|
58
|
+
<a href="/foo/bar?page=2" rel="next">2</a>
|
59
|
+
<a href="/foo/bar?page=3">3</a>
|
60
|
+
<a href="/foo/bar?page=2" class="next_page" rel="next">Next »</a></div>
|
61
|
+
HTML
|
62
|
+
expected.strip!.gsub!(/\s{2,}/, ' ')
|
63
|
+
|
64
|
+
assert_dom_equal expected, @html_result
|
65
|
+
end
|
66
|
+
|
67
|
+
## advanced options for pagination ##
|
68
|
+
|
69
|
+
def test_will_paginate_without_container
|
70
|
+
paginate({}, :container => false)
|
71
|
+
assert_select 'div.pagination', 0, 'main DIV present when it shouldn\'t'
|
72
|
+
assert_select 'a[href]', 3
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_will_paginate_without_page_links
|
76
|
+
paginate({ :page => 2 }, :page_links => false) do
|
77
|
+
assert_select 'a[href]', 2 do |elements|
|
78
|
+
validate_page_numbers [1,3], elements
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_will_paginate_windows
|
84
|
+
paginate({ :page => 6, :per_page => 1 }, :inner_window => 1) do |pagination|
|
85
|
+
assert_select 'a[href]', 8 do |elements|
|
86
|
+
validate_page_numbers [5,1,2,5,7,10,11,7], elements
|
87
|
+
assert_select elements.first, 'a', '« Previous'
|
88
|
+
assert_select elements.last, 'a', 'Next »'
|
89
|
+
end
|
90
|
+
assert_select 'span.current', '6'
|
91
|
+
assert_equal '« Previous 1 2 … 5 6 7 … 10 11 Next »', pagination.first.inner_text
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_will_paginate_eliminates_small_gaps
|
96
|
+
paginate({ :page => 6, :per_page => 1 }, :inner_window => 2) do
|
97
|
+
assert_select 'a[href]', 12 do |elements|
|
98
|
+
validate_page_numbers [5,1,2,3,4,5,7,8,9,10,11,7], elements
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_container_id
|
104
|
+
paginate do |div|
|
105
|
+
assert_nil div.first['id']
|
106
|
+
end
|
107
|
+
|
108
|
+
# magic ID
|
109
|
+
paginate({}, :id => true) do |div|
|
110
|
+
assert_equal 'fixnums_pagination', div.first['id']
|
111
|
+
end
|
112
|
+
|
113
|
+
# explicit ID
|
114
|
+
paginate({}, :id => 'custom_id') do |div|
|
115
|
+
assert_equal 'custom_id', div.first['id']
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
## other helpers ##
|
120
|
+
|
121
|
+
def test_paginated_section
|
122
|
+
@template = <<-ERB
|
123
|
+
<% paginated_section collection, options do %>
|
124
|
+
<%= content_tag :div, '', :id => "developers" %>
|
125
|
+
<% end %>
|
126
|
+
ERB
|
127
|
+
|
128
|
+
paginate
|
129
|
+
assert_select 'div.pagination', 2
|
130
|
+
assert_select 'div.pagination + div#developers', 1
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_page_entries_info
|
134
|
+
@template = '<%= page_entries_info collection %>'
|
135
|
+
array = ('a'..'z').to_a
|
136
|
+
|
137
|
+
paginate array.paginate(:page => 2, :per_page => 5)
|
138
|
+
assert_equal %{Displaying entries <b>6 - 10</b> of <b>26</b> in total},
|
139
|
+
@html_result
|
140
|
+
|
141
|
+
paginate array.paginate(:page => 7, :per_page => 4)
|
142
|
+
assert_equal %{Displaying entries <b>25 - 26</b> of <b>26</b> in total},
|
143
|
+
@html_result
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_page_entries_info_with_single_page_collection
|
147
|
+
@template = '<%= page_entries_info collection %>'
|
148
|
+
|
149
|
+
paginate(('a'..'d').to_a.paginate(:page => 1, :per_page => 5))
|
150
|
+
assert_equal %{Displaying <b>all 4</b> entries}, @html_result
|
151
|
+
|
152
|
+
paginate(['a'].paginate(:page => 1, :per_page => 5))
|
153
|
+
assert_equal %{Displaying <b>1</b> entry}, @html_result
|
154
|
+
|
155
|
+
paginate([].paginate(:page => 1, :per_page => 5))
|
156
|
+
assert_equal %{No entries found}, @html_result
|
157
|
+
end
|
158
|
+
|
159
|
+
## parameter handling in page links ##
|
160
|
+
|
161
|
+
def test_will_paginate_preserves_parameters_on_get
|
162
|
+
@request.params :foo => { :bar => 'baz' }
|
163
|
+
paginate
|
164
|
+
assert_links_match /foo%5Bbar%5D=baz/
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_will_paginate_doesnt_preserve_parameters_on_post
|
168
|
+
@request.post
|
169
|
+
@request.params :foo => 'bar'
|
170
|
+
paginate
|
171
|
+
assert_no_links_match /foo=bar/
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_adding_additional_parameters
|
175
|
+
paginate({}, :params => { :foo => 'bar' })
|
176
|
+
assert_links_match /foo=bar/
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_adding_anchor_parameter
|
180
|
+
paginate({}, :params => { :anchor => 'anchor' })
|
181
|
+
assert_links_match /#anchor$/
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_removing_arbitrary_parameters
|
185
|
+
@request.params :foo => 'bar'
|
186
|
+
paginate({}, :params => { :foo => nil })
|
187
|
+
assert_no_links_match /foo=bar/
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_adding_additional_route_parameters
|
191
|
+
paginate({}, :params => { :controller => 'baz', :action => 'list' })
|
192
|
+
assert_links_match %r{\Wbaz/list\W}
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_will_paginate_with_custom_page_param
|
196
|
+
paginate({ :page => 2 }, :param_name => :developers_page) do
|
197
|
+
assert_select 'a[href]', 4 do |elements|
|
198
|
+
validate_page_numbers [1,1,3,3], elements, :developers_page
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_complex_custom_page_param
|
204
|
+
@request.params :developers => { :page => 2 }
|
205
|
+
|
206
|
+
paginate({ :page => 2 }, :param_name => 'developers[page]') do
|
207
|
+
assert_select 'a[href]', 4 do |links|
|
208
|
+
assert_links_match /\?developers%5Bpage%5D=\d+$/, links
|
209
|
+
validate_page_numbers [1,1,3,3], links, 'developers[page]'
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_custom_routing_page_param
|
215
|
+
@request.symbolized_path_parameters.update :controller => 'dummy', :action => nil
|
216
|
+
paginate :per_page => 2 do
|
217
|
+
assert_select 'a[href]', 6 do |links|
|
218
|
+
assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2]
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_custom_routing_page_param_with_dot_separator
|
224
|
+
@request.symbolized_path_parameters.update :controller => 'dummy', :action => 'dots'
|
225
|
+
paginate :per_page => 2 do
|
226
|
+
assert_select 'a[href]', 6 do |links|
|
227
|
+
assert_links_match %r{/page\.(\d+)$}, links, [2, 3, 4, 5, 6, 2]
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
## internal hardcore stuff ##
|
233
|
+
|
234
|
+
class LegacyCollection < WillPaginate::Collection
|
235
|
+
alias :page_count :total_pages
|
236
|
+
undef :total_pages
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_deprecation_notices_with_page_count
|
240
|
+
collection = LegacyCollection.new(1, 1, 2)
|
241
|
+
|
242
|
+
assert_deprecated collection.class.name do
|
243
|
+
paginate collection
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
uses_mocha 'view internals' do
|
248
|
+
def test_collection_name_can_be_guessed
|
249
|
+
collection = mock
|
250
|
+
collection.expects(:total_pages).returns(1)
|
251
|
+
|
252
|
+
@template = '<%= will_paginate options %>'
|
253
|
+
@controller.controller_name = 'developers'
|
254
|
+
@view.assigns['developers'] = collection
|
255
|
+
|
256
|
+
paginate(nil)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_inferred_collection_name_raises_error_when_nil
|
261
|
+
@template = '<%= will_paginate options %>'
|
262
|
+
@controller.controller_name = 'developers'
|
263
|
+
|
264
|
+
e = assert_raise ArgumentError do
|
265
|
+
paginate(nil)
|
266
|
+
end
|
267
|
+
assert e.message.include?('@developers')
|
268
|
+
end
|
269
|
+
|
270
|
+
if ActionController::Base.respond_to? :rescue_responses
|
271
|
+
# only on Rails 2
|
272
|
+
def test_rescue_response_hook_presence
|
273
|
+
assert_equal :not_found,
|
274
|
+
ActionController::Base.rescue_responses['WillPaginate::InvalidPage']
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mislav-will_paginate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Mislav Marohni\xC4\x87"
|
8
|
+
- PJ Hyett
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-04-26 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: The will_paginate library provides a simple, yet powerful and extensible API for ActiveRecord pagination and rendering of pagination links in ActionView templates.
|
18
|
+
email: mislav.marohnic@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
- LICENSE
|
26
|
+
- CHANGELOG
|
27
|
+
files:
|
28
|
+
- CHANGELOG
|
29
|
+
- LICENSE
|
30
|
+
- README.rdoc
|
31
|
+
- Rakefile
|
32
|
+
- examples
|
33
|
+
- examples/apple-circle.gif
|
34
|
+
- examples/index.haml
|
35
|
+
- examples/index.html
|
36
|
+
- examples/pagination.css
|
37
|
+
- examples/pagination.sass
|
38
|
+
- init.rb
|
39
|
+
- lib
|
40
|
+
- lib/will_paginate
|
41
|
+
- lib/will_paginate.rb
|
42
|
+
- lib/will_paginate/array.rb
|
43
|
+
- lib/will_paginate/collection.rb
|
44
|
+
- lib/will_paginate/core_ext.rb
|
45
|
+
- lib/will_paginate/finder.rb
|
46
|
+
- lib/will_paginate/named_scope.rb
|
47
|
+
- lib/will_paginate/named_scope_patch.rb
|
48
|
+
- lib/will_paginate/version.rb
|
49
|
+
- lib/will_paginate/view_helpers.rb
|
50
|
+
- test
|
51
|
+
- test/boot.rb
|
52
|
+
- test/collection_test.rb
|
53
|
+
- test/console
|
54
|
+
- test/database.yml
|
55
|
+
- test/finder_test.rb
|
56
|
+
- test/fixtures
|
57
|
+
- test/fixtures/admin.rb
|
58
|
+
- test/fixtures/developer.rb
|
59
|
+
- test/fixtures/developers_projects.yml
|
60
|
+
- test/fixtures/project.rb
|
61
|
+
- test/fixtures/projects.yml
|
62
|
+
- test/fixtures/replies.yml
|
63
|
+
- test/fixtures/reply.rb
|
64
|
+
- test/fixtures/schema.rb
|
65
|
+
- test/fixtures/topic.rb
|
66
|
+
- test/fixtures/topics.yml
|
67
|
+
- test/fixtures/user.rb
|
68
|
+
- test/fixtures/users.yml
|
69
|
+
- test/helper.rb
|
70
|
+
- test/lib
|
71
|
+
- test/lib/activerecord_test_case.rb
|
72
|
+
- test/lib/activerecord_test_connector.rb
|
73
|
+
- test/lib/load_fixtures.rb
|
74
|
+
- test/lib/view_test_process.rb
|
75
|
+
- test/view_test.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://github.com/mislav/will_paginate/wikis
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options:
|
80
|
+
- --main
|
81
|
+
- README.rdoc
|
82
|
+
- --inline-source
|
83
|
+
- --charset=UTF-8
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.0.1
|
102
|
+
signing_key:
|
103
|
+
specification_version: 2
|
104
|
+
summary: Most awesome pagination solution for Rails
|
105
|
+
test_files:
|
106
|
+
- test/boot.rb
|
107
|
+
- test/collection_test.rb
|
108
|
+
- test/console
|
109
|
+
- test/database.yml
|
110
|
+
- test/finder_test.rb
|
111
|
+
- test/fixtures
|
112
|
+
- test/fixtures/admin.rb
|
113
|
+
- test/fixtures/developer.rb
|
114
|
+
- test/fixtures/developers_projects.yml
|
115
|
+
- test/fixtures/project.rb
|
116
|
+
- test/fixtures/projects.yml
|
117
|
+
- test/fixtures/replies.yml
|
118
|
+
- test/fixtures/reply.rb
|
119
|
+
- test/fixtures/schema.rb
|
120
|
+
- test/fixtures/topic.rb
|
121
|
+
- test/fixtures/topics.yml
|
122
|
+
- test/fixtures/user.rb
|
123
|
+
- test/fixtures/users.yml
|
124
|
+
- test/helper.rb
|
125
|
+
- test/lib
|
126
|
+
- test/lib/activerecord_test_case.rb
|
127
|
+
- test/lib/activerecord_test_connector.rb
|
128
|
+
- test/lib/load_fixtures.rb
|
129
|
+
- test/lib/view_test_process.rb
|
130
|
+
- test/view_test.rb
|