will_paginate 3.1.8 → 3.3.1

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
  SHA256:
3
- metadata.gz: a7e2f95ebf19f3cb09fca66deb17fbc5cafe985b102642b40ee9ca330f8228c7
4
- data.tar.gz: f9eecffdda2bdf6a08b9ff44090025725277898bb3410fc963c390c5e2e73724
3
+ metadata.gz: 3015c2c4a4d84d48b8a9c60a5ad19297e4ccbd515682df95399badb293386536
4
+ data.tar.gz: d28dd41a8fe68e9f5e43649978cb8a49b8ff03fc6fcdab303c04fcbe654a6894
5
5
  SHA512:
6
- metadata.gz: 0aae93122e8e72caff23c32c6332a959dabad21f72db562f5098dc5bb707197be11afb63eaf82a290a32a34fe3808a9eff1b3c5550e3f51c0f594d4de5abc3f4
7
- data.tar.gz: fd4e932326cea4561cf7fffba6a1a643481b00d37f7b274067ccc54be03fc820512a52fbba1075c52ff30cec1c91e3fb071d78e8754bb9d9ca19327b7bc6ad7c
6
+ metadata.gz: b6c6843a2f26883a439520ef4106124c1706c8f5deae59c16d1fee074d74a8eb50e39ef3ea8ae8dc0bd6a18331dd618c0f18079f3834b0ebda45a13f050d3f62
7
+ data.tar.gz: 5479f100b92648394d8074d2d34be19120008955ce5f5e289073eafac35389890f044d4a66fe0e54d5331fc7d6a82c17497fa800f4fee44c743939560a71af8c
data/README.md CHANGED
@@ -1,16 +1,14 @@
1
1
  # will_paginate
2
2
 
3
- will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Merb, DataMapper and Sequel.
4
-
5
- Installation:
3
+ will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, Merb, DataMapper and Sequel.
6
4
 
7
5
  ``` ruby
8
- ## Gemfile for Rails 3+, Sinatra, and Merb
9
6
  gem 'will_paginate', '~> 3.1.0'
10
7
  ```
11
8
 
12
9
  See [installation instructions][install] on the wiki for more info.
13
10
 
11
+ ℹ️ will_paginate is now in _maintenance mode_ and it will not be receiving new features. [See alternatives](https://www.ruby-toolbox.com/categories/pagination)
14
12
 
15
13
  ## Basic will_paginate use
16
14
 
@@ -105,9 +105,7 @@ module WillPaginate
105
105
  # overloaded to be pagination-aware
106
106
  def empty?
107
107
  if !loaded? and offset_value
108
- result = count
109
- result = result.size if result.respond_to?(:size) and !result.is_a?(Integer)
110
- result <= offset_value
108
+ total_entries <= offset_value
111
109
  else
112
110
  super
113
111
  end
@@ -212,6 +210,8 @@ module WillPaginate
212
210
  WHERE rownum <= #{pager.offset + pager.per_page}
213
211
  ) WHERE rnum >= #{pager.offset}
214
212
  SQL
213
+ elsif (self.connection.adapter_name =~ /^sqlserver/i)
214
+ query << " OFFSET #{pager.offset} ROWS FETCH NEXT #{pager.per_page} ROWS ONLY"
215
215
  else
216
216
  query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
217
217
  end
@@ -8,11 +8,11 @@ module WillPaginate
8
8
  Dir["#{locale_dir}/*.{rb,yml}"]
9
9
  end
10
10
 
11
- def will_paginate_translate(keys, options = {})
11
+ def will_paginate_translate(keys, options = {}, &block)
12
12
  if defined? ::I18n
13
13
  defaults = Array(keys).dup
14
- defaults << Proc.new if block_given?
15
- ::I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => :will_paginate))
14
+ defaults << block if block_given?
15
+ ::I18n.translate(defaults.shift, **options.merge(:default => defaults, :scope => :will_paginate))
16
16
  else
17
17
  key = Array === keys ? keys.first : keys
18
18
  yield key, options
@@ -3,6 +3,8 @@ en:
3
3
  previous_label: "&#8592; Previous"
4
4
  next_label: "Next &#8594;"
5
5
  page_gap: "&hellip;"
6
+ container_aria_label: "Pagination"
7
+ page_aria_label: "Page %{page}"
6
8
 
7
9
  page_entries_info:
8
10
  single_page:
@@ -8,6 +8,8 @@ module WillPaginate
8
8
  extend CollectionMethods
9
9
  @current_page = WillPaginate::PageNumber(options[:page] || @current_page || 1)
10
10
  @page_multiplier = current_page - 1
11
+ @total_entries = options.delete(:total_entries)
12
+
11
13
  pp = (options[:per_page] || per_page || WillPaginate.per_page).to_i
12
14
  limit(pp).skip(@page_multiplier * pp)
13
15
  end
@@ -1,4 +1,3 @@
1
- require 'delegate'
2
1
  require 'forwardable'
3
2
 
4
3
  module WillPaginate
@@ -6,7 +5,7 @@ module WillPaginate
6
5
  module InvalidPage; end
7
6
 
8
7
  # integer representing a page number
9
- class PageNumber < DelegateClass(Integer)
8
+ class PageNumber < Numeric
10
9
  # a value larger than this is not supported in SQL queries
11
10
  BIGINT = 9223372036854775807
12
11
 
@@ -18,13 +17,17 @@ module WillPaginate
18
17
  raise RangeError, "invalid #{name}: #{value.inspect}"
19
18
  end
20
19
  @name = name
21
- super(value)
20
+ @value = value
22
21
  rescue ArgumentError, TypeError, RangeError => error
23
22
  error.extend InvalidPage
24
23
  raise error
25
24
  end
26
25
 
27
- alias_method :to_i, :__getobj__
26
+ def to_i
27
+ @value
28
+ end
29
+
30
+ def_delegators :@value, :coerce, :==, :<=>, :to_s, :+, :-, :*, :/, :to_json
28
31
 
29
32
  def inspect
30
33
  "#{@name} #{to_i}"
@@ -40,13 +43,6 @@ module WillPaginate
40
43
  alias is_a? kind_of?
41
44
  end
42
45
 
43
- # Ultrahax: makes `Integer === current_page` checks pass
44
- Numeric.extend Module.new {
45
- def ===(obj)
46
- obj.instance_of? PageNumber or super
47
- end
48
- }
49
-
50
46
  # An idemptotent coercion method
51
47
  def self.PageNumber(value, name = 'page')
52
48
  case value
@@ -1,4 +1,3 @@
1
- require 'will_paginate'
2
1
  require 'will_paginate/page_number'
3
2
  require 'will_paginate/collection'
4
3
  require 'will_paginate/i18n'
@@ -39,7 +38,7 @@ module WillPaginate
39
38
  end
40
39
  def status_code_with_paginate(exception = @exception)
41
40
  actual_exception = if exception.respond_to?(:cause)
42
- exception.cause
41
+ exception.cause || exception
43
42
  elsif exception.respond_to?(:original_exception)
44
43
  exception.original_exception
45
44
  else
@@ -60,11 +59,11 @@ module WillPaginate
60
59
  end
61
60
 
62
61
  module ControllerRescuePatch
63
- def rescue_from(*args, &block)
62
+ def rescue_from(*args, **kwargs, &block)
64
63
  if idx = args.index(WillPaginate::InvalidPage)
65
64
  args[idx] = args[idx].name
66
65
  end
67
- super(*args, &block)
66
+ super(*args, **kwargs, &block)
68
67
  end
69
68
  end
70
69
  end
@@ -1,8 +1,8 @@
1
1
  module WillPaginate #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
- MINOR = 1
5
- TINY = 8
4
+ MINOR = 3
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -43,7 +43,7 @@ module WillPaginate
43
43
  # Wrapper for rendering pagination links at both top and bottom of a block
44
44
  # of content.
45
45
  #
46
- # <% paginated_section @posts do %>
46
+ # <%= paginated_section @posts do %>
47
47
  # <ol id="posts">
48
48
  # <% for post in @posts %>
49
49
  # <li> ... </li>
@@ -80,7 +80,7 @@ module WillPaginate
80
80
  defaults = nil
81
81
  key = keys
82
82
  end
83
- translate(key, options.merge(:default => defaults, :scope => :will_paginate))
83
+ translate(key, **options.merge(:default => defaults, :scope => :will_paginate))
84
84
  else
85
85
  super
86
86
  end
@@ -0,0 +1,41 @@
1
+ require 'hanami/view'
2
+ require 'will_paginate/view_helpers'
3
+ require 'will_paginate/view_helpers/link_renderer'
4
+
5
+ module WillPaginate
6
+ module Hanami
7
+ module Helpers
8
+ include ViewHelpers
9
+
10
+ def will_paginate(collection, options = {}) #:nodoc:
11
+ options = options.merge(:renderer => LinkRenderer) unless options[:renderer]
12
+ str = super(collection, options)
13
+ str && raw(str)
14
+ end
15
+ end
16
+
17
+ class LinkRenderer < ViewHelpers::LinkRenderer
18
+ protected
19
+
20
+ def url(page)
21
+ str = File.join(request_env['SCRIPT_NAME'].to_s, request_env['PATH_INFO'])
22
+ params = request_env['rack.request.query_hash'].merge(param_name.to_s => page.to_s)
23
+ params.update @options[:params] if @options[:params]
24
+ str << '?' << build_query(params)
25
+ end
26
+
27
+ def request_env
28
+ @template.params.env
29
+ end
30
+
31
+ def build_query(params)
32
+ Rack::Utils.build_nested_query params
33
+ end
34
+ end
35
+
36
+ def self.included(base)
37
+ base.include Helpers
38
+ end
39
+
40
+ end
41
+ end
@@ -35,16 +35,20 @@ module WillPaginate
35
35
  # Returns the subset of +options+ this instance was initialized with that
36
36
  # represent HTML attributes for the container element of pagination links.
37
37
  def container_attributes
38
- @container_attributes ||= @options.except(*(ViewHelpers.pagination_options.keys + [:renderer] - [:class]))
38
+ @container_attributes ||= {
39
+ :role => 'navigation',
40
+ :"aria-label" => @template.will_paginate_translate(:container_aria_label) { 'Pagination' }
41
+ }.update @options.except(*(ViewHelpers.pagination_options.keys + [:renderer] - [:class]))
39
42
  end
40
43
 
41
44
  protected
42
45
 
43
46
  def page_number(page)
47
+ aria_label = @template.will_paginate_translate(:page_aria_label, :page => page.to_i) { "Page #{page}" }
44
48
  if page == current_page
45
- tag(:em, page, :class => 'current')
49
+ tag(:em, page, :class => 'current', :"aria-label" => aria_label, :"aria-current" => 'page')
46
50
  else
47
- link(page, page, :rel => rel_value(page))
51
+ link(page, page, :rel => rel_value(page), :"aria-label" => aria_label)
48
52
  end
49
53
  end
50
54
 
@@ -67,7 +71,7 @@ module WillPaginate
67
71
  if page
68
72
  link(text, page, :class => classname)
69
73
  else
70
- tag(:span, text, :class => classname + ' disabled')
74
+ tag(:span, text, :class => classname + ' disabled', :"aria-disabled" => true)
71
75
  end
72
76
  end
73
77
 
data/spec/database.yml CHANGED
@@ -3,27 +3,27 @@ sqlite3:
3
3
  adapter: sqlite3
4
4
  timeout: 500
5
5
 
6
- mysql: &mysql
7
- adapter: mysql
6
+ mysql:
7
+ adapter: mysql2
8
8
  database: will_paginate
9
- username: root
9
+ username: <%= ENV["MYSQL_USER"] || "root" %>
10
10
  encoding: utf8
11
- <% if File.exist?("/var/run/mysql5/mysqld.sock") %>
11
+ <% if ENV["MYSQL_PORT"] %>
12
+ host: <%= ENV["MYSQL_HOST"] %>
13
+ port: <%= ENV["MYSQL_PORT"] %>
14
+ <% elsif File.exist?("/var/run/mysql5/mysqld.sock") %>
12
15
  host: localhost
13
16
  socket: /var/run/mysql5/mysqld.sock
14
17
  <% elsif File.exist? "/tmp/mysql.sock" %>
15
18
  host: localhost
16
19
  socket: /tmp/mysql.sock
17
- <% else %>
18
- host: 127.0.0.1
19
20
  <% end %>
20
21
 
21
- mysql2:
22
- <<: *mysql
23
- adapter: mysql2
24
-
25
22
  postgres:
26
23
  adapter: postgresql
27
24
  database: will_paginate
28
- username: <%= "postgres" if ENV["TRAVIS"] %>
29
25
  min_messages: warning
26
+ username: <%= ENV["POSTGRES_USER"] %>
27
+ password: <%= ENV["POSTGRES_PASSWORD"] %>
28
+ host: <%= ENV["POSTGRES_HOST"] %>
29
+ port: <%= ENV["POSTGRES_PORT"] %>
@@ -163,6 +163,13 @@ describe WillPaginate::ActiveRecord do
163
163
  topics.total_entries.should == 999
164
164
  end
165
165
 
166
+ it "overrides empty? count call with a total_entries fixed value" do
167
+ lambda {
168
+ topics = Topic.paginate :page => 1, :per_page => 3, :total_entries => 999
169
+ topics.should_not be_empty
170
+ }.should run_queries(0)
171
+ end
172
+
166
173
  it "removes :include for count" do
167
174
  lambda {
168
175
  developers = Developer.paginate(:page => 1, :per_page => 1).includes(:projects)
@@ -213,7 +220,7 @@ describe WillPaginate::ActiveRecord do
213
220
  sql = "select content from topics where content like '%futurama%'"
214
221
  topics = Topic.paginate_by_sql sql, :page => 1, :per_page => 1
215
222
  topics.total_entries.should == 1
216
- topics.first.attributes.has_key?('title').should be_false
223
+ topics.first.attributes.has_key?('title').should be(false)
217
224
  }.should run_queries(2)
218
225
  end
219
226
 
@@ -271,12 +278,12 @@ describe WillPaginate::ActiveRecord do
271
278
  }.should run_queries(1)
272
279
  end
273
280
 
274
- it "should get second (inexistent) page of Topics, requiring 2 queries" do
281
+ it "should get second (inexistent) page of Topics, requiring 1 query" do
275
282
  lambda {
276
283
  result = Topic.paginate :page => 2
277
284
  result.total_pages.should == 1
278
285
  result.should be_empty
279
- }.should run_queries(2)
286
+ }.should run_queries(1)
280
287
  end
281
288
 
282
289
  describe "associations" do
@@ -1,20 +1,8 @@
1
1
  require 'active_record'
2
2
  require 'active_record/fixtures'
3
- require 'active_support/multibyte' # needed for Ruby 1.9.1
4
3
  require 'stringio'
5
4
  require 'erb'
6
5
 
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
-
18
6
  $query_count = 0
19
7
  $query_sql = []
20
8
 
@@ -42,10 +30,6 @@ module ActiverecordTestConnector
42
30
 
43
31
  FIXTURES_PATH = File.expand_path('../../fixtures', __FILE__)
44
32
 
45
- Fixtures = defined?(ActiveRecord::FixtureSet) ? ActiveRecord::FixtureSet :
46
- defined?(ActiveRecord::Fixtures) ? ActiveRecord::Fixtures :
47
- ::Fixtures
48
-
49
33
  # Set our defaults
50
34
  self.connected = false
51
35
 
@@ -79,13 +63,6 @@ module ActiverecordTestConnector
79
63
  ActiveRecord::Base.configurations = { db => configuration }
80
64
  ActiveRecord::Base.establish_connection(db.to_sym)
81
65
  ActiveRecord::Base.default_timezone = :utc
82
-
83
- case configuration['adapter']
84
- when 'mysql'
85
- fix_primary_key(ActiveRecord::ConnectionAdapters::MysqlAdapter)
86
- when 'mysql2'
87
- fix_primary_key(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
88
- end
89
66
  end
90
67
 
91
68
  def load_schema
@@ -98,37 +75,27 @@ module ActiverecordTestConnector
98
75
  end
99
76
  end
100
77
 
101
- def fix_primary_key(adapter_class)
102
- if ActiveRecord::VERSION::STRING < "4.1"
103
- adapter_class::NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
104
- end
105
- end
106
-
107
78
  module FixtureSetup
108
79
  def fixtures(*tables)
109
80
  table_names = tables.map { |t| t.to_s }
110
81
 
111
- fixtures = Fixtures.create_fixtures ActiverecordTestConnector::FIXTURES_PATH, table_names
82
+ fixtures = ActiveRecord::FixtureSet.create_fixtures(ActiverecordTestConnector::FIXTURES_PATH, table_names)
112
83
  @@loaded_fixtures = {}
113
84
  @@fixture_cache = {}
114
85
 
115
86
  unless fixtures.nil?
116
- if fixtures.instance_of?(Fixtures)
117
- @@loaded_fixtures[fixtures.table_name] = fixtures
118
- else
119
- fixtures.each { |f| @@loaded_fixtures[f.table_name] = f }
120
- end
87
+ fixtures.each { |f| @@loaded_fixtures[f.table_name] = f }
121
88
  end
122
89
 
123
90
  table_names.each do |table_name|
124
- define_method(table_name) do |*fixtures|
91
+ define_method(table_name) do |*names|
125
92
  @@fixture_cache[table_name] ||= {}
126
93
 
127
- instances = fixtures.map do |fixture|
128
- if @@loaded_fixtures[table_name][fixture.to_s]
129
- @@fixture_cache[table_name][fixture] ||= @@loaded_fixtures[table_name][fixture.to_s].find
94
+ instances = names.map do |name|
95
+ if @@loaded_fixtures[table_name][name.to_s]
96
+ @@fixture_cache[table_name][name] ||= @@loaded_fixtures[table_name][name.to_s].find
130
97
  else
131
- raise StandardError, "No fixture with name '#{fixture}' found for table '#{table_name}'"
98
+ raise StandardError, "No fixture with name '#{name}' found for table '#{table_name}'"
132
99
  end
133
100
  end
134
101
 
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'will_paginate/page_number'
3
+ require 'json'
3
4
 
4
5
  describe WillPaginate::PageNumber do
5
6
  describe "valid" do
@@ -37,7 +38,14 @@ describe WillPaginate::PageNumber do
37
38
 
38
39
  it "passes the Numeric=== type check" do |variable|
39
40
  (Numeric === num).should be
40
- (Integer === num).should be
41
+ end
42
+
43
+ it "fails the Numeric=== type check" do |variable|
44
+ (Integer === num).should_not be
45
+ end
46
+
47
+ it "serializes as JSON number" do
48
+ JSON.dump(page: num).should eq('{"page":12}')
41
49
  end
42
50
  end
43
51
 
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,5 @@
1
1
  require 'rspec'
2
2
  require 'view_helpers/view_example_group'
3
- begin
4
- require 'ruby-debug'
5
- rescue LoadError
6
- # no debugger available
7
- end
8
3
 
9
4
  Dir[File.expand_path('../matchers/*_matcher.rb', __FILE__)].each { |matcher| require matcher }
10
5
 
@@ -42,5 +37,5 @@ RSpec.configure do |config|
42
37
  }
43
38
 
44
39
  config.mock_with :mocha
45
- config.backtrace_clean_patterns << /view_example_group/
40
+ config.backtrace_exclusion_patterns << /view_example_group/
46
41
  end
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
- require 'active_support/rescuable' # needed for Ruby 1.9.1
4
3
  require 'action_controller'
5
4
  require 'action_view'
6
5
  require 'will_paginate/view_helpers/action_view'
@@ -14,7 +13,8 @@ Routes.draw do
14
13
  get 'ibocorp(/:page)' => 'ibocorp#index',
15
14
  :constraints => { :page => /\d+/ }, :defaults => { :page => 1 }
16
15
 
17
- get ':controller(/:action(/:id(.:format)))'
16
+ get 'foo/bar' => 'foo#bar'
17
+ get 'baz/list' => 'baz#list'
18
18
  end
19
19
 
20
20
  describe WillPaginate::ActionView do
@@ -22,6 +22,8 @@ describe WillPaginate::ActionView do
22
22
  before(:all) do
23
23
  I18n.load_path.concat WillPaginate::I18n.load_path
24
24
  I18n.enforce_available_locales = false
25
+
26
+ ActionController::Parameters.permit_all_parameters = false
25
27
  end
26
28
 
27
29
  before(:each) do
@@ -38,7 +40,12 @@ describe WillPaginate::ActionView do
38
40
  attr_reader :assigns, :controller, :request
39
41
 
40
42
  def render(locals)
41
- @view = ActionView::Base.new([], @assigns, @controller)
43
+ lookup_context = []
44
+ lookup_context = ActionView::LookupContext.new(lookup_context)
45
+
46
+ klass = ActionView::Base
47
+ klass = klass.with_empty_template_cache if klass.respond_to?(:with_empty_template_cache)
48
+ @view = klass.new(lookup_context, @assigns, @controller)
42
49
  @view.request = @request
43
50
  @view.singleton_class.send(:include, @controller._routes.url_helpers)
44
51
  @view.render(:inline => @template, :locals => locals)
@@ -120,16 +127,20 @@ describe WillPaginate::ActionView do
120
127
  it "should match expected markup" do
121
128
  paginate
122
129
  expected = <<-HTML
123
- <div class="pagination"><span class="previous_page disabled">&#8592; Previous</span>
124
- <em class="current">1</em>
125
- <a href="/foo/bar?page=2" rel="next">2</a>
126
- <a href="/foo/bar?page=3">3</a>
130
+ <div class="pagination" role="navigation" aria-label="Pagination"><span class="previous_page disabled" aria-disabled="true">&#8592; Previous</span>
131
+ <em class="current" aria-label="Page 1" aria-current="page">1</em>
132
+ <a href="/foo/bar?page=2" aria-label="Page 2" rel="next">2</a>
133
+ <a href="/foo/bar?page=3" aria-label="Page 3">3</a>
127
134
  <a href="/foo/bar?page=2" class="next_page" rel="next">Next &#8594;</a></div>
128
135
  HTML
129
136
  expected.strip!.gsub!(/\s{2,}/, ' ')
130
- expected_dom = parse_html_document(expected).root
137
+ expected_dom = parse_html_document(expected)
131
138
 
132
- html_document.root.should == expected_dom
139
+ if expected_dom.respond_to?(:canonicalize)
140
+ html_document.canonicalize.should == expected_dom.canonicalize
141
+ else
142
+ html_document.root.should == expected_dom.root
143
+ end
133
144
  end
134
145
 
135
146
  it "should output escaped URLs" do
@@ -358,6 +369,16 @@ describe WillPaginate::ActionView do
358
369
  end
359
370
  end
360
371
 
372
+ # TODO: re-enable once Rails 6.1.4 ships
373
+ xit "page_entries_info" do
374
+ @template = "<%= page_entries_info collection, options %>"
375
+ output = render(
376
+ collection: WillPaginate::Collection.new(1, 1, 3),
377
+ options: {html: false},
378
+ )
379
+ output.should == "Displaying entries 1 - 0 of 3 in total"
380
+ end
381
+
361
382
  private
362
383
 
363
384
  def translation(data)
@@ -442,11 +463,7 @@ class DummyRequest
442
463
 
443
464
  def params(more = nil)
444
465
  @params.update(more) if more
445
- if defined?(ActionController::Parameters)
446
- ActionController::Parameters.new(@params)
447
- else
448
- @params
449
- end
466
+ ActionController::Parameters.new(@params)
450
467
  end
451
468
 
452
469
  def host_with_port
@@ -462,7 +479,3 @@ class DummyRequest
462
479
  'http:'
463
480
  end
464
481
  end
465
-
466
- if defined?(ActionController::Parameters)
467
- ActionController::Parameters.permit_all_parameters = false
468
- end
@@ -1,30 +1,13 @@
1
1
  require 'active_support'
2
2
  require 'stringio'
3
- begin
4
- $stderr = StringIO.new
5
- require 'minitest/unit'
6
- rescue LoadError
7
- # Fails on Ruby 1.8, but it's OK since we only need MiniTest::Assertions
8
- # on Rails 4 which doesn't support 1.8 anyway.
9
- ensure
10
- $stderr = STDERR
11
- end
12
-
13
- begin
14
- require 'rails/dom/testing/assertions'
15
- rescue LoadError
16
- require 'action_dispatch/testing/assertions'
17
- end
3
+ require 'minitest/assertions'
4
+ require 'rails/dom/testing/assertions'
18
5
  require 'will_paginate/array'
19
6
 
20
7
  module ViewExampleGroup
21
8
 
22
- if defined?(Rails::Dom::Testing::Assertions)
23
- include Rails::Dom::Testing::Assertions::SelectorAssertions
24
- else
25
- include ActionDispatch::Assertions::SelectorAssertions
26
- end
27
- include MiniTest::Assertions if defined? MiniTest
9
+ include Rails::Dom::Testing::Assertions::SelectorAssertions
10
+ include Minitest::Assertions
28
11
 
29
12
  def assert(value, message)
30
13
  raise message unless value
@@ -50,11 +33,7 @@ module ViewExampleGroup
50
33
  end
51
34
 
52
35
  def parse_html_document(html)
53
- @html_document ||= if defined?(Rails::Dom::Testing::Assertions)
54
- Nokogiri::HTML::Document.parse(html)
55
- else
56
- HTML::Document.new(html, true, false)
57
- end
36
+ Nokogiri::HTML::Document.parse(html)
58
37
  end
59
38
 
60
39
  def html_document
@@ -124,23 +103,3 @@ RSpec.configure do |config|
124
103
  :file_path => %r{spec/view_helpers/}
125
104
  }
126
105
  end
127
-
128
- module HTML
129
- Node.class_eval do
130
- def inner_text
131
- children.map(&:inner_text).join('')
132
- end
133
- end
134
-
135
- Text.class_eval do
136
- def inner_text
137
- self.to_s
138
- end
139
- end
140
-
141
- Tag.class_eval do
142
- def inner_text
143
- childless?? '' : super
144
- end
145
- end
146
- end if defined?(HTML)
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.8
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mislav Marohnić
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-19 00:00:00.000000000 Z
11
+ date: 2021-08-12 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
15
- links in Rails, Sinatra and Merb web apps.
15
+ links in Rails, Sinatra, Hanami, and Merb web apps.
16
16
  email: mislav.marohnic@gmail.com
17
17
  executables: []
18
18
  extensions: []
@@ -39,6 +39,7 @@ files:
39
39
  - lib/will_paginate/version.rb
40
40
  - lib/will_paginate/view_helpers.rb
41
41
  - lib/will_paginate/view_helpers/action_view.rb
42
+ - lib/will_paginate/view_helpers/hanami.rb
42
43
  - lib/will_paginate/view_helpers/link_renderer.rb
43
44
  - lib/will_paginate/view_helpers/link_renderer_base.rb
44
45
  - lib/will_paginate/view_helpers/merb.rb
@@ -47,14 +48,8 @@ files:
47
48
  - spec/console
48
49
  - spec/console_fixtures.rb
49
50
  - spec/database.yml
50
- - spec/fake_rubygems.rb
51
51
  - spec/finders/active_record_spec.rb
52
52
  - spec/finders/activerecord_test_connector.rb
53
- - spec/finders/data_mapper_spec.rb
54
- - spec/finders/data_mapper_test_connector.rb
55
- - spec/finders/mongoid_spec.rb
56
- - spec/finders/sequel_spec.rb
57
- - spec/finders/sequel_test_connector.rb
58
53
  - spec/fixtures/admin.rb
59
54
  - spec/fixtures/developer.rb
60
55
  - spec/fixtures/developers_projects.yml
@@ -77,11 +72,16 @@ files:
77
72
  - spec/view_helpers/base_spec.rb
78
73
  - spec/view_helpers/link_renderer_base_spec.rb
79
74
  - spec/view_helpers/view_example_group.rb
80
- homepage: https://github.com/mislav/will_paginate/wiki
75
+ homepage: https://github.com/mislav/will_paginate
81
76
  licenses:
82
77
  - MIT
83
- metadata: {}
84
- post_install_message:
78
+ metadata:
79
+ bug_tracker_uri: https://github.com/mislav/will_paginate/issues
80
+ changelog_uri: https://github.com/mislav/will_paginate/releases/tag/v3.3.1
81
+ documentation_uri: https://www.rubydoc.info/gems/will_paginate/3.3.1
82
+ source_code_uri: https://github.com/mislav/will_paginate/tree/v3.3.1
83
+ wiki_uri: https://github.com/mislav/will_paginate/wiki
84
+ post_install_message:
85
85
  rdoc_options:
86
86
  - "--main"
87
87
  - README.md
@@ -92,16 +92,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
- version: '0'
95
+ version: '2.0'
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - ">="
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.7.6
104
- signing_key:
102
+ rubygems_version: 3.1.4
103
+ signing_key:
105
104
  specification_version: 4
106
105
  summary: Pagination plugin for web frameworks and other apps
107
106
  test_files: []
@@ -1,18 +0,0 @@
1
- # Makes the test suite compatible with Bundler standalone mode (used in CI)
2
- # because Active Record uses `gem` for loading adapters.
3
- Kernel.module_eval do
4
-
5
- remove_method :gem if 'method' == defined? gem
6
-
7
- def gem(*args)
8
- return if $VERBOSE.nil?
9
- $stderr << "warning: gem(#{args.map {|o| o.inspect }.join(', ')}) ignored"
10
- $stderr << "; called from:\n " << caller[0,5].join("\n ") if $DEBUG
11
- $stderr << "\n"
12
- end
13
-
14
- private :gem
15
-
16
- end
17
-
18
- $" << "rubygems.rb"
@@ -1,114 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if !ENV['SKIP_NONRAILS_TESTS']
4
- require 'will_paginate/data_mapper'
5
- require File.expand_path('../data_mapper_test_connector', __FILE__)
6
- datamapper_loaded = true
7
- else
8
- datamapper_loaded = false
9
- end
10
-
11
- describe WillPaginate::DataMapper do
12
-
13
- it "has per_page" do
14
- Animal.per_page.should == 30
15
- begin
16
- Animal.per_page = 10
17
- Animal.per_page.should == 10
18
-
19
- subclass = Class.new(Animal)
20
- subclass.per_page.should == 10
21
- ensure
22
- Animal.per_page = 30
23
- end
24
- end
25
-
26
- it "doesn't make normal collections appear paginated" do
27
- Animal.all.should_not be_paginated
28
- end
29
-
30
- it "paginates to first page by default" do
31
- animals = Animal.paginate(:page => nil)
32
-
33
- animals.should be_paginated
34
- animals.current_page.should == 1
35
- animals.per_page.should == 30
36
- animals.offset.should == 0
37
- animals.total_entries.should == 3
38
- animals.total_pages.should == 1
39
- end
40
-
41
- it "paginates to first page, explicit limit" do
42
- animals = Animal.paginate(:page => 1, :per_page => 2)
43
-
44
- animals.current_page.should == 1
45
- animals.per_page.should == 2
46
- animals.total_entries.should == 3
47
- animals.total_pages.should == 2
48
- animals.map {|a| a.name }.should == %w[ Dog Cat ]
49
- end
50
-
51
- it "paginates to second page" do
52
- animals = Animal.paginate(:page => 2, :per_page => 2)
53
-
54
- animals.current_page.should == 2
55
- animals.offset.should == 2
56
- animals.map {|a| a.name }.should == %w[ Lion ]
57
- end
58
-
59
- it "paginates a collection" do
60
- friends = Animal.all(:notes.like => '%friend%')
61
- friends.paginate(:page => 1).per_page.should == 30
62
- friends.paginate(:page => 1, :per_page => 1).total_entries.should == 2
63
- end
64
-
65
- it "paginates a limited collection" do
66
- animals = Animal.all(:limit => 2).paginate(:page => 1)
67
- animals.per_page.should == 2
68
- end
69
-
70
- it "has page() method" do
71
- Animal.page(2).per_page.should == 30
72
- Animal.page(2).offset.should == 30
73
- Animal.page(2).current_page.should == 2
74
- Animal.all(:limit => 2).page(2).per_page.should == 2
75
- end
76
-
77
- it "has total_pages at 1 for empty collections" do
78
- Animal.all(:conditions => ['1=2']).page(1).total_pages.should == 1
79
- end
80
-
81
- it "overrides total_entries count with a fixed value" do
82
- lambda {
83
- animals = Animal.paginate :page => 1, :per_page => 3, :total_entries => 999
84
- animals.total_entries.should == 999
85
- }.should run_queries(0)
86
- end
87
-
88
- it "supports a non-int for total_entries" do
89
- topics = Animal.paginate :page => 1, :per_page => 3, :total_entries => "999"
90
- topics.total_entries.should == 999
91
- end
92
-
93
-
94
- it "can iterate and then call WP methods" do
95
- animals = Animal.all(:limit => 2).page(1)
96
- animals.each { |a| }
97
- animals.total_entries.should == 3
98
- end
99
-
100
- it "augments to_a to return a WP::Collection" do
101
- animals = Animal.all(:limit => 2).page(1)
102
- array = animals.to_a
103
- array.size.should == 2
104
- array.should be_kind_of(WillPaginate::Collection)
105
- array.current_page.should == 1
106
- array.per_page.should == 2
107
- end
108
-
109
- it "doesn't have a problem assigning has-one-through relationship" do
110
- human = Human.create :name => "Mislav"
111
- human.pet = Animal.first
112
- end
113
-
114
- end if datamapper_loaded
@@ -1,54 +0,0 @@
1
- require 'sqlite3'
2
- require 'dm-core'
3
- require 'dm-core/support/logger'
4
- require 'dm-migrations'
5
-
6
- DataMapper.setup :default, 'sqlite3::memory:'
7
-
8
- # Define models
9
- class Animal
10
- include DataMapper::Resource
11
- property :id, Serial
12
- property :name, String
13
- property :notes, Text
14
-
15
- def self.setup
16
- Animal.create(:name => 'Dog', :notes => "Man's best friend")
17
- Animal.create(:name => 'Cat', :notes => "Woman's best friend")
18
- Animal.create(:name => 'Lion', :notes => 'King of the Jungle')
19
- end
20
- end
21
-
22
- class Ownership
23
- include DataMapper::Resource
24
-
25
- belongs_to :animal, :key => true
26
- belongs_to :human, :key => true
27
-
28
- def self.setup
29
- end
30
- end
31
-
32
- class Human
33
- include DataMapper::Resource
34
-
35
- property :id, Serial
36
- property :name, String
37
-
38
- has n, :ownerships
39
- has 1, :pet, :model => 'Animal', :through => :ownerships, :via => :animal
40
-
41
- def self.setup
42
- end
43
- end
44
-
45
- # Load fixtures
46
- [Animal, Ownership, Human].each do |klass|
47
- klass.auto_migrate!
48
- klass.setup
49
- end
50
-
51
- if 'irb' == $0
52
- DataMapper.logger.set_log($stdout, :debug)
53
- DataMapper.logger.auto_flush = true
54
- end
@@ -1,145 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if !ENV['SKIP_NONRAILS_TESTS']
4
- if defined?(Rails)
5
- old_rails = Rails
6
- # Mongoid sees the `Rails` constant and then proceeds to `require "rails"`
7
- # from its railtie. This tricks it into believing there is no Rails.
8
- Object.send(:remove_const, :Rails)
9
- end
10
- require 'will_paginate/mongoid'
11
- Object.send(:const_set, :Rails, old_rails) if old_rails
12
-
13
- Mongoid.connect_to 'will_paginate_test'
14
- class MongoidModel
15
- include Mongoid::Document
16
- end
17
-
18
- mongoid_loaded = true
19
- else
20
- mongoid_loaded = false
21
- end
22
-
23
- describe WillPaginate::Mongoid do
24
- before(:all) do
25
- MongoidModel.delete_all
26
- 4.times { MongoidModel.create! }
27
- end
28
-
29
- let(:criteria) { MongoidModel.criteria }
30
-
31
- describe "#page" do
32
- it "should forward to the paginate method" do
33
- criteria.expects(:paginate).with(:page => 2).returns("itself")
34
- criteria.page(2).should == "itself"
35
- end
36
-
37
- it "should not override per_page if set earlier in the chain" do
38
- criteria.paginate(:per_page => 10).page(1).per_page.should == 10
39
- criteria.paginate(:per_page => 20).page(1).per_page.should == 20
40
- end
41
- end
42
-
43
- describe "#per_page" do
44
- it "should set the limit if given an argument" do
45
- criteria.per_page(10).options[:limit].should == 10
46
- end
47
-
48
- it "should return the current limit if no argument is given" do
49
- criteria.per_page.should == nil
50
- criteria.per_page(10).per_page.should == 10
51
- end
52
-
53
- it "should be interchangable with limit" do
54
- criteria.limit(15).per_page.should == 15
55
- end
56
-
57
- it "should be nil'able" do
58
- criteria.per_page(nil).per_page.should be_nil
59
- end
60
- end
61
-
62
- describe "#paginate" do
63
- it "should use criteria" do
64
- criteria.paginate.should be_instance_of(::Mongoid::Criteria)
65
- end
66
-
67
- it "should not override page number if set earlier in the chain" do
68
- criteria.page(3).paginate.current_page.should == 3
69
- end
70
-
71
- it "should limit according to per_page parameter" do
72
- criteria.paginate(:per_page => 10).options.should include(:limit => 10)
73
- end
74
-
75
- it "should skip according to page and per_page parameters" do
76
- criteria.paginate(:page => 2, :per_page => 5).options.should include(:skip => 5)
77
- end
78
-
79
- specify "first fallback value for per_page option is the current limit" do
80
- criteria.limit(12).paginate.options.should include(:limit => 12)
81
- end
82
-
83
- specify "second fallback value for per_page option is WillPaginate.per_page" do
84
- criteria.paginate.options.should include(:limit => WillPaginate.per_page)
85
- end
86
-
87
- specify "page should default to 1" do
88
- criteria.paginate.options.should include(:skip => 0)
89
- end
90
-
91
- it "should convert strings to integers" do
92
- criteria.paginate(:page => "2", :per_page => "3").options.should include(:limit => 3)
93
- end
94
-
95
- describe "collection compatibility" do
96
- describe "#total_count" do
97
- it "should be calculated correctly" do
98
- criteria.paginate(:per_page => 1).total_entries.should == 4
99
- criteria.paginate(:per_page => 3).total_entries.should == 4
100
- end
101
-
102
- it "should be cached" do
103
- criteria.expects(:count).once.returns(123)
104
- criteria.paginate
105
- 2.times { criteria.total_entries.should == 123 }
106
- end
107
- end
108
-
109
- it "should calculate total_pages" do
110
- criteria.paginate(:per_page => 1).total_pages.should == 4
111
- criteria.paginate(:per_page => 3).total_pages.should == 2
112
- criteria.paginate(:per_page => 10).total_pages.should == 1
113
- end
114
-
115
- it "should return per_page" do
116
- criteria.paginate(:per_page => 1).per_page.should == 1
117
- criteria.paginate(:per_page => 5).per_page.should == 5
118
- end
119
-
120
- describe "#current_page" do
121
- it "should return current_page" do
122
- criteria.paginate(:page => 1).current_page.should == 1
123
- criteria.paginate(:page => 3).current_page.should == 3
124
- end
125
-
126
- it "should be casted to PageNumber" do
127
- page = criteria.paginate(:page => 1).current_page
128
- (page.instance_of? WillPaginate::PageNumber).should be
129
- end
130
- end
131
-
132
- it "should return offset" do
133
- criteria.paginate(:page => 1).offset.should == 0
134
- criteria.paginate(:page => 2, :per_page => 5).offset.should == 5
135
- criteria.paginate(:page => 3, :per_page => 10).offset.should == 20
136
- end
137
-
138
- it "should not pollute plain mongoid criterias" do
139
- %w(total_entries total_pages current_page).each do |method|
140
- criteria.should_not respond_to(method)
141
- end
142
- end
143
- end
144
- end
145
- end if mongoid_loaded
@@ -1,65 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if !ENV['SKIP_NONRAILS_TESTS']
4
- require 'will_paginate/sequel'
5
- require File.expand_path('../sequel_test_connector', __FILE__)
6
- sequel_loaded = true
7
- else
8
- sequel_loaded = false
9
- end
10
-
11
- describe Sequel::Dataset::Pagination, 'extension' do
12
-
13
- class Car < Sequel::Model
14
- end
15
-
16
- it "should have the #paginate method" do
17
- Car.should respond_to(:paginate)
18
- end
19
-
20
- it "should NOT have the #paginate_by_sql method" do
21
- Car.should_not respond_to(:paginate_by_sql)
22
- end
23
-
24
- describe 'pagination' do
25
- before(:all) do
26
- Car.create(:name => 'Shelby', :notes => "Man's best friend")
27
- Car.create(:name => 'Aston Martin', :notes => "Woman's best friend")
28
- Car.create(:name => 'Corvette', :notes => 'King of the Jungle')
29
- end
30
-
31
- it "should imitate WillPaginate::Collection" do
32
- result = Car.paginate(1, 2)
33
-
34
- result.should_not be_empty
35
- result.size.should == 2
36
- result.length.should == 2
37
- result.total_entries.should == 3
38
- result.total_pages.should == 2
39
- result.per_page.should == 2
40
- result.current_page.should == 1
41
- end
42
-
43
- it "should perform" do
44
- Car.paginate(1, 2).all.should == [Car[1], Car[2]]
45
- end
46
-
47
- it "should be empty" do
48
- result = Car.paginate(3, 2)
49
- result.should be_empty
50
- end
51
-
52
- it "should perform with #select and #order" do
53
- result = Car.select("name as foo".lit).order(:name).paginate(1, 2).all
54
- result.size.should == 2
55
- result.first.values[:foo].should == "Aston Martin"
56
- end
57
-
58
- it "should perform with #filter" do
59
- results = Car.filter(:name => 'Shelby').paginate(1, 2).all
60
- results.size.should == 1
61
- results.first.should == Car.find(:name => 'Shelby')
62
- end
63
- end
64
-
65
- end if sequel_loaded
@@ -1,15 +0,0 @@
1
- require 'sequel'
2
-
3
- Symbol.class_eval do
4
- # Active Record calculations tries `as` on some objects but chokes when that
5
- # object was a Symbol and it gets a Sequel::SQL::AliasedExpression.
6
- undef as if method_defined? :as
7
- end
8
-
9
- db = Sequel.sqlite
10
-
11
- db.create_table :cars do
12
- primary_key :id, :integer, :auto_increment => true
13
- column :name, :text
14
- column :notes, :text
15
- end