will_paginate 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of will_paginate might be problematic. Click here for more details.
- data/CHANGELOG +32 -2
- data/LICENSE +1 -1
- data/{README → README.rdoc} +42 -59
- data/Rakefile +41 -4
- 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 +34 -11
- data/lib/will_paginate/array.rb +16 -0
- data/lib/will_paginate/collection.rb +37 -24
- data/lib/will_paginate/core_ext.rb +1 -49
- data/lib/will_paginate/finder.rb +29 -4
- data/lib/will_paginate/named_scope.rb +132 -0
- data/lib/will_paginate/named_scope_patch.rb +50 -0
- data/lib/will_paginate/version.rb +1 -1
- data/lib/will_paginate/view_helpers.rb +123 -21
- data/test/boot.rb +0 -2
- data/test/{array_pagination_test.rb → collection_test.rb} +37 -28
- data/test/console +2 -3
- data/test/database.yml +22 -0
- data/test/finder_test.rb +150 -56
- data/test/fixtures/developer.rb +2 -0
- data/test/fixtures/projects.yml +3 -4
- data/test/fixtures/reply.rb +2 -0
- data/test/fixtures/topic.rb +2 -0
- data/test/helper.rb +13 -1
- data/test/lib/activerecord_test_case.rb +14 -1
- data/test/lib/activerecord_test_connector.rb +19 -10
- data/test/lib/load_fixtures.rb +3 -5
- data/test/lib/view_test_process.rb +73 -0
- data/test/view_test.rb +314 -0
- metadata +32 -31
- data/Manifest.txt +0 -34
- data/config/release.rb +0 -82
- data/setup.rb +0 -1585
- data/test/pagination_test.rb +0 -257
data/test/lib/load_fixtures.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require File.join(dirname, 'activerecord_test_connector')
|
1
|
+
require 'boot'
|
2
|
+
require 'lib/activerecord_test_connector'
|
4
3
|
|
5
4
|
# setup the connection
|
6
5
|
ActiveRecordTestConnector.setup
|
7
6
|
|
8
7
|
# load all fixtures
|
9
|
-
|
10
|
-
Fixtures.create_fixtures(fixture_path, ActiveRecord::Base.connection.tables)
|
8
|
+
Fixtures.create_fixtures(ActiveRecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables)
|
11
9
|
|
12
10
|
require 'will_paginate'
|
13
11
|
WillPaginate.enable_activerecord
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
require 'action_controller/test_process'
|
3
|
+
|
4
|
+
require 'will_paginate'
|
5
|
+
WillPaginate.enable_actionpack
|
6
|
+
|
7
|
+
ActionController::Routing::Routes.draw do |map|
|
8
|
+
map.connect ':controller/:action/:id'
|
9
|
+
end
|
10
|
+
|
11
|
+
ActionController::Base.perform_caching = false
|
12
|
+
|
13
|
+
class DummyRequest
|
14
|
+
def initialize
|
15
|
+
@get = true
|
16
|
+
@params = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def get?
|
20
|
+
@get
|
21
|
+
end
|
22
|
+
|
23
|
+
def post
|
24
|
+
@get = false
|
25
|
+
end
|
26
|
+
|
27
|
+
def symbolized_path_parameters
|
28
|
+
{ :controller => 'foo', :action => 'bar' }
|
29
|
+
end
|
30
|
+
|
31
|
+
def relative_url_root
|
32
|
+
''
|
33
|
+
end
|
34
|
+
|
35
|
+
def params(more = nil)
|
36
|
+
@params.update(more) if more
|
37
|
+
@params
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class DummyController
|
42
|
+
attr_reader :request
|
43
|
+
attr_accessor :controller_name
|
44
|
+
|
45
|
+
def initialize
|
46
|
+
@request = DummyRequest.new
|
47
|
+
@url = ActionController::UrlRewriter.new(@request, @request.params)
|
48
|
+
end
|
49
|
+
|
50
|
+
def url_for(params)
|
51
|
+
@url.rewrite(params)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module HTML
|
56
|
+
Node.class_eval do
|
57
|
+
def inner_text
|
58
|
+
children.map(&:inner_text).join('')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
Text.class_eval do
|
63
|
+
def inner_text
|
64
|
+
self.to_s
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Tag.class_eval do
|
69
|
+
def inner_text
|
70
|
+
childless?? '' : super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/test/view_test.rb
ADDED
@@ -0,0 +1,314 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'lib/view_test_process'
|
4
|
+
|
5
|
+
class ViewTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
@controller = DummyController.new
|
10
|
+
@request = @controller.request
|
11
|
+
@html_result = nil
|
12
|
+
@template = '<%= will_paginate collection, options %>'
|
13
|
+
|
14
|
+
@view = ActionView::Base.new
|
15
|
+
@view.assigns['controller'] = @controller
|
16
|
+
@view.assigns['_request'] = @request
|
17
|
+
@view.assigns['_params'] = @request.params
|
18
|
+
end
|
19
|
+
|
20
|
+
## basic pagination ##
|
21
|
+
|
22
|
+
def test_will_paginate
|
23
|
+
paginate do |pagination|
|
24
|
+
assert_select 'a[href]', 3 do |elements|
|
25
|
+
validate_page_numbers [2,3,2], elements
|
26
|
+
assert_select elements.last, ':last-child', "Next »"
|
27
|
+
end
|
28
|
+
assert_select 'span', 2
|
29
|
+
assert_select 'span.disabled:first-child', '« Previous'
|
30
|
+
assert_select 'span.current', '1'
|
31
|
+
assert_equal '« Previous 1 2 3 Next »', pagination.first.inner_text
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_no_pagination_when_page_count_is_one
|
36
|
+
paginate :per_page => 30
|
37
|
+
assert_equal '', @html_result
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_will_paginate_with_options
|
41
|
+
paginate({ :page => 2 },
|
42
|
+
:class => 'will_paginate', :prev_label => 'Prev', :next_label => 'Next') do
|
43
|
+
assert_select 'a[href]', 4 do |elements|
|
44
|
+
validate_page_numbers [1,1,3,3], elements
|
45
|
+
# test rel attribute values:
|
46
|
+
assert_select elements[1], 'a', '1' do |link|
|
47
|
+
assert_equal 'prev start', link.first['rel']
|
48
|
+
end
|
49
|
+
assert_select elements.first, 'a', "Prev" do |link|
|
50
|
+
assert_equal 'prev start', link.first['rel']
|
51
|
+
end
|
52
|
+
assert_select elements.last, 'a', "Next" do |link|
|
53
|
+
assert_equal 'next', link.first['rel']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
assert_select 'span.current', '2'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_prev_next_links_have_classnames
|
61
|
+
paginate do |pagination|
|
62
|
+
assert_select 'span.disabled.prev_page:first-child'
|
63
|
+
assert_select 'a.next_page[href]:last-child'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_full_output
|
68
|
+
paginate
|
69
|
+
expected = <<-HTML
|
70
|
+
<div class="pagination"><span class="disabled prev_page">« Previous</span>
|
71
|
+
<span class="current">1</span>
|
72
|
+
<a href="/foo/bar?page=2" rel="next">2</a>
|
73
|
+
<a href="/foo/bar?page=3">3</a>
|
74
|
+
<a href="/foo/bar?page=2" class="next_page" rel="next">Next »</a></div>
|
75
|
+
HTML
|
76
|
+
expected.strip!.gsub!(/\s{2,}/, ' ')
|
77
|
+
|
78
|
+
assert_dom_equal expected, @html_result
|
79
|
+
end
|
80
|
+
|
81
|
+
## advanced options for pagination ##
|
82
|
+
|
83
|
+
def test_will_paginate_without_container
|
84
|
+
paginate({}, :container => false)
|
85
|
+
assert_select 'div.pagination', 0, 'main DIV present when it shouldn\'t'
|
86
|
+
assert_select 'a[href]', 3
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_will_paginate_without_page_links
|
90
|
+
paginate({ :page => 2 }, :page_links => false) do
|
91
|
+
assert_select 'a[href]', 2 do |elements|
|
92
|
+
validate_page_numbers [1,3], elements
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_will_paginate_windows
|
98
|
+
paginate({ :page => 6, :per_page => 1 }, :inner_window => 1) do |pagination|
|
99
|
+
assert_select 'a[href]', 8 do |elements|
|
100
|
+
validate_page_numbers [5,1,2,5,7,10,11,7], elements
|
101
|
+
assert_select elements.first, 'a', '« Previous'
|
102
|
+
assert_select elements.last, 'a', 'Next »'
|
103
|
+
end
|
104
|
+
assert_select 'span.current', '6'
|
105
|
+
assert_equal '« Previous 1 2 … 5 6 7 … 10 11 Next »', pagination.first.inner_text
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_will_paginate_eliminates_small_gaps
|
110
|
+
paginate({ :page => 6, :per_page => 1 }, :inner_window => 2) do
|
111
|
+
assert_select 'a[href]', 12 do |elements|
|
112
|
+
validate_page_numbers [5,1,2,3,4,5,7,8,9,10,11,7], elements
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_container_id
|
118
|
+
paginate do |div|
|
119
|
+
assert_nil div.first['id']
|
120
|
+
end
|
121
|
+
|
122
|
+
# magic ID
|
123
|
+
paginate({}, :id => true) do |div|
|
124
|
+
assert_equal 'fixnums_pagination', div.first['id']
|
125
|
+
end
|
126
|
+
|
127
|
+
# explicit ID
|
128
|
+
paginate({}, :id => 'custom_id') do |div|
|
129
|
+
assert_equal 'custom_id', div.first['id']
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
## other helpers ##
|
134
|
+
|
135
|
+
def test_paginated_section
|
136
|
+
@template = <<-ERB
|
137
|
+
<% paginated_section collection, options do %>
|
138
|
+
<%= content_tag :div, '', :id => "developers" %>
|
139
|
+
<% end %>
|
140
|
+
ERB
|
141
|
+
|
142
|
+
paginate
|
143
|
+
assert_select 'div.pagination', 2
|
144
|
+
assert_select 'div.pagination + div#developers', 1
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_page_entries_info
|
148
|
+
@template = '<%= page_entries_info collection %>'
|
149
|
+
array = ('a'..'z').to_a
|
150
|
+
|
151
|
+
paginate array.paginate(:page => 2, :per_page => 5)
|
152
|
+
assert_equal %{Displaying entries <b>6 - 10</b> of <b>26</b> in total},
|
153
|
+
@html_result
|
154
|
+
|
155
|
+
paginate array.paginate(:page => 7, :per_page => 4)
|
156
|
+
assert_equal %{Displaying entries <b>25 - 26</b> of <b>26</b> in total},
|
157
|
+
@html_result
|
158
|
+
end
|
159
|
+
|
160
|
+
## parameter handling in page links ##
|
161
|
+
|
162
|
+
def test_will_paginate_preserves_parameters_on_get
|
163
|
+
@request.params :foo => { :bar => 'baz' }
|
164
|
+
paginate
|
165
|
+
assert_links_match /foo%5Bbar%5D=baz/
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_will_paginate_doesnt_preserve_parameters_on_post
|
169
|
+
@request.post
|
170
|
+
@request.params :foo => 'bar'
|
171
|
+
paginate
|
172
|
+
assert_no_links_match /foo=bar/
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_adding_additional_parameters
|
176
|
+
paginate({}, :params => { :foo => 'bar' })
|
177
|
+
assert_links_match /foo=bar/
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_removing_arbitrary_parameters
|
181
|
+
@request.params :foo => 'bar'
|
182
|
+
paginate({}, :params => { :foo => nil })
|
183
|
+
assert_no_links_match /foo=bar/
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_adding_additional_route_parameters
|
187
|
+
paginate({}, :params => { :controller => 'baz', :action => 'list' })
|
188
|
+
assert_links_match %r{\Wbaz/list\W}
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_will_paginate_with_custom_page_param
|
192
|
+
paginate({ :page => 2 }, :param_name => :developers_page) do
|
193
|
+
assert_select 'a[href]', 4 do |elements|
|
194
|
+
validate_page_numbers [1,1,3,3], elements, :developers_page
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_complex_custom_page_param
|
200
|
+
@request.params :developers => { :page => 2 }
|
201
|
+
|
202
|
+
paginate({ :page => 2 }, :param_name => 'developers[page]') do
|
203
|
+
assert_select 'a[href]', 4 do |links|
|
204
|
+
assert_links_match /\?developers%5Bpage%5D=\d+$/, links
|
205
|
+
validate_page_numbers [1,1,3,3], links, 'developers[page]'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
## internal hardcore stuff ##
|
211
|
+
|
212
|
+
class LegacyCollection < WillPaginate::Collection
|
213
|
+
alias :page_count :total_pages
|
214
|
+
undef :total_pages
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_deprecation_notices_with_page_count
|
218
|
+
collection = LegacyCollection.new(1, 1, 2)
|
219
|
+
|
220
|
+
assert_deprecated collection.class.name do
|
221
|
+
paginate collection
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
uses_mocha 'view internals' do
|
226
|
+
def test_collection_name_can_be_guessed
|
227
|
+
collection = mock
|
228
|
+
collection.expects(:total_pages).returns(1)
|
229
|
+
|
230
|
+
@template = '<%= will_paginate options %>'
|
231
|
+
@controller.controller_name = 'developers'
|
232
|
+
@view.assigns['developers'] = collection
|
233
|
+
|
234
|
+
paginate(nil)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_inferred_collection_name_raises_error_when_nil
|
239
|
+
@template = '<%= will_paginate options %>'
|
240
|
+
@controller.controller_name = 'developers'
|
241
|
+
|
242
|
+
e = assert_raise ArgumentError do
|
243
|
+
paginate(nil)
|
244
|
+
end
|
245
|
+
assert e.message.include?('@developers')
|
246
|
+
end
|
247
|
+
|
248
|
+
if ActionController::Base.respond_to? :rescue_responses
|
249
|
+
# only on Rails 2
|
250
|
+
def test_rescue_response_hook_presence
|
251
|
+
assert_equal :not_found,
|
252
|
+
ActionController::Base.rescue_responses['WillPaginate::InvalidPage']
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
protected
|
258
|
+
|
259
|
+
def paginate(collection = {}, options = {}, &block)
|
260
|
+
if collection.instance_of? Hash
|
261
|
+
page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection)
|
262
|
+
collection = [1].paginate(page_options)
|
263
|
+
end
|
264
|
+
|
265
|
+
locals = { :collection => collection, :options => options }
|
266
|
+
|
267
|
+
if defined? ActionView::Template
|
268
|
+
# Rails 2.1
|
269
|
+
args = [ ActionView::Template.new(@view, @template, false, locals, true, nil) ]
|
270
|
+
else
|
271
|
+
# older Rails versions
|
272
|
+
args = [nil, @template, nil, locals]
|
273
|
+
end
|
274
|
+
|
275
|
+
@html_result = @view.render_template(*args)
|
276
|
+
@html_document = HTML::Document.new(@html_result, true, false)
|
277
|
+
|
278
|
+
if block_given?
|
279
|
+
classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class]
|
280
|
+
assert_select("div.#{classname}", 1, 'no main DIV', &block)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
def response_from_page_or_rjs
|
285
|
+
@html_document.root
|
286
|
+
end
|
287
|
+
|
288
|
+
def validate_page_numbers expected, links, param_name = :page
|
289
|
+
param_pattern = /\W#{CGI.escape(param_name.to_s)}=([^&]*)/
|
290
|
+
|
291
|
+
assert_equal(expected, links.map { |e|
|
292
|
+
e['href'] =~ param_pattern
|
293
|
+
$1 ? $1.to_i : $1
|
294
|
+
})
|
295
|
+
end
|
296
|
+
|
297
|
+
def assert_links_match pattern, links = nil
|
298
|
+
links ||= assert_select 'div.pagination a[href]' do |elements|
|
299
|
+
elements
|
300
|
+
end
|
301
|
+
|
302
|
+
links.each do |el|
|
303
|
+
assert_match pattern, el['href']
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def assert_no_links_match pattern
|
308
|
+
assert_select 'div.pagination a[href]' do |elements|
|
309
|
+
elements.each do |el|
|
310
|
+
assert_no_match pattern, el['href']
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
metadata
CHANGED
@@ -1,54 +1,56 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: will_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Mislav Marohni\xC4\x87"
|
8
|
-
- PJ Hyett
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
11
|
|
13
|
-
date: 2008-
|
12
|
+
date: 2008-04-07 00:00:00 +02:00
|
14
13
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
|
17
|
-
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.4.4
|
24
|
-
version:
|
25
|
-
description: A Rails plugin that provides pagination solutions for querying models and rendering pagination links in views.
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
26
17
|
email: mislav.marohnic@gmail.com
|
27
18
|
executables: []
|
28
19
|
|
29
20
|
extensions: []
|
30
21
|
|
31
|
-
extra_rdoc_files:
|
32
|
-
|
33
|
-
- LICENSE
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
34
24
|
files:
|
35
25
|
- CHANGELOG
|
36
26
|
- LICENSE
|
37
|
-
-
|
38
|
-
- README
|
27
|
+
- README.rdoc
|
39
28
|
- Rakefile
|
40
|
-
-
|
29
|
+
- examples
|
30
|
+
- examples/apple-circle.gif
|
31
|
+
- examples/index.haml
|
32
|
+
- examples/index.html
|
33
|
+
- examples/pagination.css
|
34
|
+
- examples/pagination.sass
|
35
|
+
- init.rb
|
36
|
+
- lib
|
37
|
+
- lib/will_paginate
|
41
38
|
- lib/will_paginate.rb
|
39
|
+
- lib/will_paginate/array.rb
|
42
40
|
- lib/will_paginate/collection.rb
|
43
41
|
- lib/will_paginate/core_ext.rb
|
44
42
|
- lib/will_paginate/finder.rb
|
43
|
+
- lib/will_paginate/named_scope.rb
|
44
|
+
- lib/will_paginate/named_scope_patch.rb
|
45
45
|
- lib/will_paginate/version.rb
|
46
46
|
- lib/will_paginate/view_helpers.rb
|
47
|
-
-
|
48
|
-
- test/array_pagination_test.rb
|
47
|
+
- test
|
49
48
|
- test/boot.rb
|
49
|
+
- test/collection_test.rb
|
50
50
|
- test/console
|
51
|
+
- test/database.yml
|
51
52
|
- test/finder_test.rb
|
53
|
+
- test/fixtures
|
52
54
|
- test/fixtures/admin.rb
|
53
55
|
- test/fixtures/developer.rb
|
54
56
|
- test/fixtures/developers_projects.yml
|
@@ -62,18 +64,17 @@ files:
|
|
62
64
|
- test/fixtures/user.rb
|
63
65
|
- test/fixtures/users.yml
|
64
66
|
- test/helper.rb
|
67
|
+
- test/lib
|
65
68
|
- test/lib/activerecord_test_case.rb
|
66
69
|
- test/lib/activerecord_test_connector.rb
|
67
70
|
- test/lib/load_fixtures.rb
|
68
|
-
- test/
|
71
|
+
- test/lib/view_test_process.rb
|
72
|
+
- test/view_test.rb
|
69
73
|
has_rdoc: true
|
70
|
-
homepage: http://github.com/mislav/will_paginate
|
74
|
+
homepage: http://github.com/mislav/will_paginate
|
71
75
|
post_install_message:
|
72
|
-
rdoc_options:
|
73
|
-
|
74
|
-
- README
|
75
|
-
- --inline-source
|
76
|
-
- --charset=UTF-8
|
76
|
+
rdoc_options: []
|
77
|
+
|
77
78
|
require_paths:
|
78
79
|
- lib
|
79
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -91,9 +92,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
requirements: []
|
92
93
|
|
93
94
|
rubyforge_project: will-paginate
|
94
|
-
rubygems_version: 1.0
|
95
|
+
rubygems_version: 1.1.0
|
95
96
|
signing_key:
|
96
97
|
specification_version: 2
|
97
|
-
summary:
|
98
|
+
summary: Most awesome pagination solution for Rails
|
98
99
|
test_files: []
|
99
100
|
|