will_paginate 3.0.7 → 3.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1868f72daf66f8ede4a9253c2b09f8f31b139491
4
- data.tar.gz: 6c3e2f25535acb3ec0be32c3352d4007405debf8
3
+ metadata.gz: 578bfcd70a16322ebd1801e1c4a8c76a4ed0a334
4
+ data.tar.gz: 2cdd8ab00a1283414888adc8ed64bbd7446223cf
5
5
  SHA512:
6
- metadata.gz: 3ca8c0a4b2e6f3be74b770618fc46f54a729171936b5e39c46425b8c9e48aa61701713825a6a6ab973a93c732886f582366878235624901d06119f94a7ba675d
7
- data.tar.gz: 1127948955580aa81cdaeea1e028f0abec34743e1047bfd659c3152d372bb41299ff7336710b8ef77aeb885b53241f077e93be90e000a1feeb6e602b72447607
6
+ metadata.gz: 36e1ec8a34231aefd0a13ccc77afc09951762eefba81c11fb23561ebdff6914dc941e04b0c5209444afa1893e70463dc137f4b8eb1c0e6337cf35182a88faded
7
+ data.tar.gz: 2bb06f172cdbc858e2bbbbce3582757b0b2f1a65fdcae9be930b44a00551ecd64ceb585f43279f5ebf9989e0c406fc4aa3399c7f2b2536041b1e86949a5bbef7
@@ -10,7 +10,7 @@ module WillPaginate::Deprecation
10
10
  private
11
11
 
12
12
  def rails_logger
13
- defined?(Rails) && Rails.logger
13
+ defined?(Rails.logger) && Rails.logger
14
14
  end
15
15
 
16
16
  def origin_of_call(stack)
@@ -32,14 +32,17 @@ module WillPaginate
32
32
  end
33
33
 
34
34
  def self.add_locale_path(config)
35
- config.i18n.railties_load_path.unshift(*WillPaginate::I18n.load_path)
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 { alias_method_chain :status_code, :paginate }
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) &&
@@ -2,7 +2,7 @@ module WillPaginate #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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
@@ -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
- socket: <%= ENV["BOXEN_MYSQL_SOCKET"] %>
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.find(:all, :order => 'projects.id', :limit => 4)
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 |
@@ -1,3 +1,3 @@
1
1
  class Admin < User
2
- has_many :companies, :finder_sql => 'SELECT * FROM companies'
2
+ has_many :companies
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class Developer < User
2
- has_and_belongs_to_many :projects, :order => 'projects.name', :join_table => 'developers_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' }
@@ -1,5 +1,5 @@
1
1
  class Project < ActiveRecord::Base
2
- has_and_belongs_to_many :developers, :uniq => true, :join_table => 'developers_projects'
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})',
@@ -3,23 +3,41 @@ require 'will_paginate/page_number'
3
3
 
4
4
  describe WillPaginate::PageNumber do
5
5
  describe "valid" do
6
- subject { described_class.new('12', 'page') }
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 { should eq(12) }
9
- its(:inspect) { should eq('page 12') }
10
- it { should be_a(WillPaginate::PageNumber) }
11
- it { should be_instance_of(WillPaginate::PageNumber) }
12
- it { should be_a(Numeric) }
13
- it { should be_a(Fixnum) }
14
- it { should_not be_instance_of(Fixnum) }
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 === subject).should be
35
+ (WillPaginate::PageNumber === num).should be
18
36
  end
19
37
 
20
38
  it "passes the Numeric=== type check" do |variable|
21
- (Numeric === subject).should be
22
- (Fixnum === subject).should be
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
- assert_select elements.last, ':last-child', "Next &#8594;"
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', '&#8592; Previous'
55
59
  assert_select 'em.current', '1'
56
- pagination.first.inner_text.should == '&#8592; Previous 1 2 3 Next &#8594;'
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
- assert_select elements[1], 'a', '1' do |link|
79
- link.first['rel'].should == 'prev start'
80
- end
81
- assert_select elements.first, 'a', "Prev" do |link|
82
- link.first['rel'].should == 'prev start'
83
- end
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 &#8594;</a></div>
127
128
  HTML
128
129
  expected.strip!.gsub!(/\s{2,}/, ' ')
129
- expected_dom = HTML::Document.new(expected).root
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.split('&amp;').sort.should == %w(page=2 tag=%3Cbr%3E)
141
+ parts = query.gsub('&amp;', '&').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 => nil
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 => nil
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('&#8594;', '→').gsub('&#8592;', '←')
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
@@ -10,6 +10,7 @@ describe WillPaginate::ViewHelpers do
10
10
  before(:all) do
11
11
  # make sure default translations aren't loaded
12
12
  I18n.load_path.clear
13
+ I18n.enforce_available_locales = false
13
14
  end
14
15
 
15
16
  before(:each) do
@@ -9,12 +9,21 @@ rescue LoadError
9
9
  ensure
10
10
  $stderr = STDERR
11
11
  end
12
- require 'action_dispatch/testing/assertions'
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
- include ActionDispatch::Assertions::SelectorAssertions
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 ||= HTML::Document.new(@render_output, true, false)
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.7
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: 2014-07-04 00:00:00.000000000 Z
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.2.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