will_paginate 3.0.7 → 3.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/will_paginate/deprecation.rb +1 -1
- data/lib/will_paginate/railtie.rb +5 -2
- data/lib/will_paginate/version.rb +1 -1
- data/lib/will_paginate/view_helpers/action_view.rb +3 -1
- data/lib/will_paginate/view_helpers/link_renderer.rb +3 -2
- data/spec/database.yml +11 -7
- data/spec/finders/active_record_spec.rb +1 -1
- data/spec/finders/activerecord_test_connector.rb +12 -1
- data/spec/fixtures/admin.rb +1 -1
- data/spec/fixtures/developer.rb +1 -1
- data/spec/fixtures/project.rb +1 -1
- data/spec/page_number_spec.rb +29 -11
- data/spec/view_helpers/action_view_spec.rb +40 -21
- data/spec/view_helpers/base_spec.rb +1 -0
- data/spec/view_helpers/view_example_group.rb +27 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 578bfcd70a16322ebd1801e1c4a8c76a4ed0a334
|
4
|
+
data.tar.gz: 2cdd8ab00a1283414888adc8ed64bbd7446223cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e1ec8a34231aefd0a13ccc77afc09951762eefba81c11fb23561ebdff6914dc941e04b0c5209444afa1893e70463dc137f4b8eb1c0e6337cf35182a88faded
|
7
|
+
data.tar.gz: 2bb06f172cdbc858e2bbbbce3582757b0b2f1a65fdcae9be930b44a00551ecd64ceb585f43279f5ebf9989e0c406fc4aa3399c7f2b2536041b1e86949a5bbef7
|
@@ -32,14 +32,17 @@ module WillPaginate
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.add_locale_path(config)
|
35
|
-
config.i18n.
|
35
|
+
config.i18n.load_path.unshift(*WillPaginate::I18n.load_path)
|
36
36
|
end
|
37
37
|
|
38
38
|
# Extending the exception handler middleware so it properly detects
|
39
39
|
# WillPaginate::InvalidPage regardless of it being a tag module.
|
40
40
|
module ShowExceptionsPatch
|
41
41
|
extend ActiveSupport::Concern
|
42
|
-
included
|
42
|
+
included do
|
43
|
+
alias_method :status_code_without_paginate, :status_code
|
44
|
+
alias_method :status_code, :status_code_with_paginate
|
45
|
+
end
|
43
46
|
def status_code_with_paginate(exception = @exception)
|
44
47
|
if exception.is_a?(WillPaginate::InvalidPage) or
|
45
48
|
(exception.respond_to?(:original_exception) &&
|
@@ -99,6 +99,8 @@ module WillPaginate
|
|
99
99
|
class LinkRenderer < ViewHelpers::LinkRenderer
|
100
100
|
protected
|
101
101
|
|
102
|
+
GET_PARAMS_BLACKLIST = [:script_name]
|
103
|
+
|
102
104
|
def default_url_params
|
103
105
|
{}
|
104
106
|
end
|
@@ -118,7 +120,7 @@ module WillPaginate
|
|
118
120
|
|
119
121
|
def merge_get_params(url_params)
|
120
122
|
if @template.respond_to? :request and @template.request and @template.request.get?
|
121
|
-
symbolized_update(url_params, @template.params)
|
123
|
+
symbolized_update(url_params, @template.params, GET_PARAMS_BLACKLIST)
|
122
124
|
end
|
123
125
|
url_params
|
124
126
|
end
|
@@ -114,11 +114,12 @@ module WillPaginate
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
def symbolized_update(target, other)
|
117
|
+
def symbolized_update(target, other, blacklist = nil)
|
118
118
|
other.each do |key, value|
|
119
119
|
key = key.to_sym
|
120
120
|
existing = target[key]
|
121
|
-
|
121
|
+
next if blacklist && blacklist.include?(key)
|
122
|
+
|
122
123
|
if value.is_a?(Hash) and (existing.is_a?(Hash) or existing.nil?)
|
123
124
|
symbolized_update(existing || (target[key] = {}), value)
|
124
125
|
else
|
data/spec/database.yml
CHANGED
@@ -3,23 +3,27 @@ sqlite3:
|
|
3
3
|
adapter: sqlite3
|
4
4
|
timeout: 500
|
5
5
|
|
6
|
-
mysql:
|
6
|
+
mysql: &mysql
|
7
7
|
adapter: mysql
|
8
8
|
database: will_paginate
|
9
9
|
username:
|
10
10
|
encoding: utf8
|
11
|
-
|
11
|
+
<% if File.exist?("/var/run/mysql5/mysqld.sock") %>
|
12
|
+
host: localhost
|
13
|
+
socket: /var/run/mysql5/mysqld.sock
|
14
|
+
<% elsif File.exist? "/tmp/mysql.sock" %>
|
15
|
+
host: localhost
|
16
|
+
socket: /tmp/mysql.sock
|
17
|
+
<% else %>
|
18
|
+
host: 127.0.0.1
|
19
|
+
<% end %>
|
12
20
|
|
13
21
|
mysql2:
|
22
|
+
<<: *mysql
|
14
23
|
adapter: mysql2
|
15
|
-
database: will_paginate
|
16
|
-
username:
|
17
|
-
encoding: utf8
|
18
|
-
socket: <%= ENV["BOXEN_MYSQL_SOCKET"] %>
|
19
24
|
|
20
25
|
postgres:
|
21
26
|
adapter: postgresql
|
22
27
|
database: will_paginate
|
23
28
|
username: <%= "postgres" if ENV["TRAVIS"] %>
|
24
29
|
min_messages: warning
|
25
|
-
port: <%= ENV["BOXEN_POSTGRESQL_PORT"] %>
|
@@ -387,7 +387,7 @@ describe WillPaginate::ActiveRecord do
|
|
387
387
|
result.total_entries.should == 2
|
388
388
|
|
389
389
|
lambda {
|
390
|
-
dhh.projects.
|
390
|
+
dhh.projects.order('projects.id').limit(4).to_a
|
391
391
|
}.should_not raise_error
|
392
392
|
|
393
393
|
result = dhh.projects.paginate(:page => 1, :per_page => 4).reorder('projects.id')
|
@@ -4,12 +4,23 @@ require 'active_support/multibyte' # needed for Ruby 1.9.1
|
|
4
4
|
require 'stringio'
|
5
5
|
require 'erb'
|
6
6
|
|
7
|
+
# https://travis-ci.org/mislav/will_paginate/jobs/99999001
|
8
|
+
require 'active_support/core_ext/string/conversions'
|
9
|
+
class String
|
10
|
+
alias to_datetime_without_patch to_datetime
|
11
|
+
def to_datetime
|
12
|
+
to_datetime_without_patch
|
13
|
+
rescue ArgumentError
|
14
|
+
return nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
7
18
|
$query_count = 0
|
8
19
|
$query_sql = []
|
9
20
|
|
10
21
|
ignore_sql = /
|
11
22
|
^(
|
12
|
-
PRAGMA | SHOW\ max_identifier_length |
|
23
|
+
PRAGMA | SHOW\ (max_identifier_length|search_path) |
|
13
24
|
SELECT\ (currval|CAST|@@IDENTITY|@@ROWCOUNT) |
|
14
25
|
SHOW\ ((FULL\ )?FIELDS|TABLES)
|
15
26
|
)\b |
|
data/spec/fixtures/admin.rb
CHANGED
data/spec/fixtures/developer.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Developer < User
|
2
|
-
has_and_belongs_to_many :projects, :
|
2
|
+
has_and_belongs_to_many :projects, :join_table => 'developers_projects'
|
3
3
|
|
4
4
|
def self.with_poor_ones(&block)
|
5
5
|
options = { :conditions => ['salary <= ?', 80000], :order => 'salary' }
|
data/spec/fixtures/project.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Project < ActiveRecord::Base
|
2
|
-
has_and_belongs_to_many :developers, :
|
2
|
+
has_and_belongs_to_many :developers, :join_table => 'developers_projects'
|
3
3
|
|
4
4
|
has_many :topics
|
5
5
|
# :finder_sql => 'SELECT * FROM topics WHERE (topics.project_id = #{id})',
|
data/spec/page_number_spec.rb
CHANGED
@@ -3,23 +3,41 @@ require 'will_paginate/page_number'
|
|
3
3
|
|
4
4
|
describe WillPaginate::PageNumber do
|
5
5
|
describe "valid" do
|
6
|
-
|
6
|
+
def num
|
7
|
+
WillPaginate::PageNumber.new('12', 'page')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "== 12" do
|
11
|
+
num.should eq(12)
|
12
|
+
end
|
7
13
|
|
8
|
-
it
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
it
|
13
|
-
|
14
|
-
|
14
|
+
it "inspects to 'page 12'" do
|
15
|
+
num.inspect.should eq('page 12')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "is a PageNumber" do
|
19
|
+
(num.instance_of? WillPaginate::PageNumber).should be
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is a kind of Numeric" do
|
23
|
+
(num.is_a? Numeric).should be
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is a kind of Fixnum" do
|
27
|
+
(num.is_a? Fixnum).should be
|
28
|
+
end
|
29
|
+
|
30
|
+
it "isn't directly a Fixnum" do
|
31
|
+
(num.instance_of? Fixnum).should_not be
|
32
|
+
end
|
15
33
|
|
16
34
|
it "passes the PageNumber=== type check" do |variable|
|
17
|
-
(WillPaginate::PageNumber ===
|
35
|
+
(WillPaginate::PageNumber === num).should be
|
18
36
|
end
|
19
37
|
|
20
38
|
it "passes the Numeric=== type check" do |variable|
|
21
|
-
(Numeric ===
|
22
|
-
(Fixnum ===
|
39
|
+
(Numeric === num).should be
|
40
|
+
(Fixnum === num).should be
|
23
41
|
end
|
24
42
|
end
|
25
43
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'spec_helper'
|
2
3
|
require 'active_support/rescuable' # needed for Ruby 1.9.1
|
3
4
|
require 'action_controller'
|
@@ -20,6 +21,7 @@ describe WillPaginate::ActionView do
|
|
20
21
|
|
21
22
|
before(:all) do
|
22
23
|
I18n.load_path.concat WillPaginate::I18n.load_path
|
24
|
+
I18n.enforce_available_locales = false
|
23
25
|
end
|
24
26
|
|
25
27
|
before(:each) do
|
@@ -48,12 +50,14 @@ describe WillPaginate::ActionView do
|
|
48
50
|
paginate do |pagination|
|
49
51
|
assert_select 'a[href]', 3 do |elements|
|
50
52
|
validate_page_numbers [2,3,2], elements
|
51
|
-
|
53
|
+
text(elements[2]).should == 'Next →'
|
54
|
+
end
|
55
|
+
assert_select 'span', 1 do |spans|
|
56
|
+
spans[0]['class'].should == 'previous_page disabled'
|
57
|
+
text(spans[0]).should == '← Previous'
|
52
58
|
end
|
53
|
-
assert_select 'span', 1
|
54
|
-
assert_select 'span.disabled:first-child', '← Previous'
|
55
59
|
assert_select 'em.current', '1'
|
56
|
-
pagination.
|
60
|
+
text(pagination[0]).should == '← Previous 1 2 3 Next →'
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
@@ -75,15 +79,12 @@ describe WillPaginate::ActionView do
|
|
75
79
|
assert_select 'a[href]', 4 do |elements|
|
76
80
|
validate_page_numbers [1,1,3,3], elements
|
77
81
|
# test rel attribute values:
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
assert_select elements.last, 'a', "Next" do |link|
|
85
|
-
link.first['rel'].should == 'next'
|
86
|
-
end
|
82
|
+
text(elements[0]).should == 'Prev'
|
83
|
+
elements[0]['rel'].should == 'prev start'
|
84
|
+
text(elements[1]).should == '1'
|
85
|
+
elements[1]['rel'].should == 'prev start'
|
86
|
+
text(elements[3]).should == 'Next'
|
87
|
+
elements[3]['rel'].should == 'next'
|
87
88
|
end
|
88
89
|
assert_select '.current', '2'
|
89
90
|
end
|
@@ -126,8 +127,8 @@ describe WillPaginate::ActionView do
|
|
126
127
|
<a href="/foo/bar?page=2" class="next_page" rel="next">Next →</a></div>
|
127
128
|
HTML
|
128
129
|
expected.strip!.gsub!(/\s{2,}/, ' ')
|
129
|
-
expected_dom =
|
130
|
-
|
130
|
+
expected_dom = parse_html_document(expected).root
|
131
|
+
|
131
132
|
html_document.root.should == expected_dom
|
132
133
|
end
|
133
134
|
|
@@ -137,7 +138,8 @@ describe WillPaginate::ActionView do
|
|
137
138
|
|
138
139
|
assert_select 'a[href]', 1 do |links|
|
139
140
|
query = links.first['href'].split('?', 2)[1]
|
140
|
-
query.
|
141
|
+
parts = query.gsub('&', '&').split('&').sort
|
142
|
+
parts.should == %w(page=2 tag=%3Cbr%3E)
|
141
143
|
end
|
142
144
|
end
|
143
145
|
|
@@ -199,6 +201,13 @@ describe WillPaginate::ActionView do
|
|
199
201
|
assert_no_links_match /99/
|
200
202
|
assert_no_links_match /ftp/
|
201
203
|
end
|
204
|
+
|
205
|
+
it "doesn't allow tampering with script_name" do
|
206
|
+
request.params :script_name => 'p0wned'
|
207
|
+
paginate
|
208
|
+
assert_links_match %r{^/foo/bar}
|
209
|
+
assert_no_links_match /p0wned/
|
210
|
+
end
|
202
211
|
|
203
212
|
it "should not preserve parameters on POST" do
|
204
213
|
request.post
|
@@ -248,7 +257,7 @@ describe WillPaginate::ActionView do
|
|
248
257
|
end
|
249
258
|
|
250
259
|
it "should paginate with custom route page parameter" do
|
251
|
-
request.symbolized_path_parameters.update :controller => 'dummy', :action =>
|
260
|
+
request.symbolized_path_parameters.update :controller => 'dummy', :action => 'index'
|
252
261
|
paginate :per_page => 2 do
|
253
262
|
assert_select 'a[href]', 6 do |links|
|
254
263
|
assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2]
|
@@ -266,7 +275,7 @@ describe WillPaginate::ActionView do
|
|
266
275
|
end
|
267
276
|
|
268
277
|
it "should paginate with custom route and first page number implicit" do
|
269
|
-
request.symbolized_path_parameters.update :controller => 'ibocorp', :action =>
|
278
|
+
request.symbolized_path_parameters.update :controller => 'ibocorp', :action => 'index'
|
270
279
|
paginate :page => 2, :per_page => 2 do
|
271
280
|
assert_select 'a[href]', 7 do |links|
|
272
281
|
assert_links_match %r{/ibocorp(?:/(\d+))?$}, links, [nil, nil, 3, 4, 5, 6, 3]
|
@@ -355,6 +364,11 @@ describe WillPaginate::ActionView do
|
|
355
364
|
I18n.available_locales # triggers loading existing translations
|
356
365
|
I18n.backend.store_translations(:en, data)
|
357
366
|
end
|
367
|
+
|
368
|
+
# Normalizes differences between HTML::Document and Nokogiri::HTML
|
369
|
+
def text(node)
|
370
|
+
node.inner_text.gsub('→', '→').gsub('←', '←')
|
371
|
+
end
|
358
372
|
end
|
359
373
|
|
360
374
|
class AdditionalLinkAttributesRenderer < WillPaginate::ActionView::LinkRenderer
|
@@ -376,7 +390,7 @@ class DummyController
|
|
376
390
|
include Routes.url_helpers
|
377
391
|
|
378
392
|
def initialize
|
379
|
-
@request = DummyRequest.new
|
393
|
+
@request = DummyRequest.new(self)
|
380
394
|
end
|
381
395
|
|
382
396
|
def params
|
@@ -399,12 +413,17 @@ class DummyRequest
|
|
399
413
|
attr_accessor :symbolized_path_parameters
|
400
414
|
alias :path_parameters :symbolized_path_parameters
|
401
415
|
|
402
|
-
def initialize
|
416
|
+
def initialize(controller)
|
417
|
+
@controller = controller
|
403
418
|
@get = true
|
404
419
|
@params = {}
|
405
420
|
@symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
|
406
421
|
end
|
407
|
-
|
422
|
+
|
423
|
+
def routes
|
424
|
+
@controller._routes
|
425
|
+
end
|
426
|
+
|
408
427
|
def get?
|
409
428
|
@get
|
410
429
|
end
|
@@ -9,12 +9,21 @@ rescue LoadError
|
|
9
9
|
ensure
|
10
10
|
$stderr = STDERR
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'rails/dom/testing/assertions'
|
15
|
+
rescue LoadError
|
16
|
+
require 'action_dispatch/testing/assertions'
|
17
|
+
end
|
13
18
|
require 'will_paginate/array'
|
14
19
|
|
15
20
|
module ViewExampleGroup
|
16
21
|
|
17
|
-
|
22
|
+
if defined?(Rails::Dom::Testing::Assertions)
|
23
|
+
include Rails::Dom::Testing::Assertions::SelectorAssertions
|
24
|
+
else
|
25
|
+
include ActionDispatch::Assertions::SelectorAssertions
|
26
|
+
end
|
18
27
|
include MiniTest::Assertions if defined? MiniTest
|
19
28
|
|
20
29
|
def assert(value, message)
|
@@ -40,11 +49,23 @@ module ViewExampleGroup
|
|
40
49
|
|
41
50
|
@render_output
|
42
51
|
end
|
43
|
-
|
52
|
+
|
53
|
+
def parse_html_document(html)
|
54
|
+
@html_document ||= if defined?(Rails::Dom::Testing::Assertions)
|
55
|
+
Nokogiri::HTML::Document.parse(html)
|
56
|
+
else
|
57
|
+
HTML::Document.new(html, true, false)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
44
61
|
def html_document
|
45
|
-
@html_document ||=
|
62
|
+
@html_document ||= parse_html_document(@render_output)
|
46
63
|
end
|
47
|
-
|
64
|
+
|
65
|
+
def document_root_element
|
66
|
+
html_document.root
|
67
|
+
end
|
68
|
+
|
48
69
|
def response_from_page_or_rjs
|
49
70
|
html_document.root
|
50
71
|
end
|
@@ -123,4 +144,4 @@ module HTML
|
|
123
144
|
childless?? '' : super
|
124
145
|
end
|
125
146
|
end
|
126
|
-
end
|
147
|
+
end if defined?(HTML)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: will_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mislav Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: will_paginate provides a simple API for performing paginated queries
|
14
14
|
with Active Record, DataMapper and Sequel, and includes helpers for rendering pagination
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
100
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
101
|
+
rubygems_version: 2.5.1
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: Pagination plugin for web frameworks and other apps
|