will_paginate 3.1.3 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fef2cd8f47f945a1b5d7378a4c66ceba6dc49cdb
4
- data.tar.gz: af9aa669e248488ec198d5239172fcf08fead4a1
2
+ SHA256:
3
+ metadata.gz: a6263dfb6824224c74e2383ba39b7f35abe25288dfcdd89a3dbab6f2585eb91e
4
+ data.tar.gz: c26bb41e5bf140fd2564ed63fda7ed4822f3c126a6a3b3885b27e2585dbf3647
5
5
  SHA512:
6
- metadata.gz: ea9ced53320267da3646dad5102f408ed8cc5ad7d973f0a91893035d6ef671c1d57ab5b8793b6002d84ca71363618948718f3ee8cfdd4f3b01e0628eebb96434
7
- data.tar.gz: c0571c50659366d61692379a97fbaff6f012529f38dc617a5efba1a24a1d9a3a687e95777ef4da6c96b9f0f94ee8380d6ce80b62b8ce7a2b36d95fb66c352eb3
6
+ metadata.gz: 8f67913552fff8839f5de82d9e55c61ad69c1a57216da3d5d627aef77455ee32a03d2b8c2b732299b37481ea6e9fd72a5baa1432e1fe296e78fc06b6a46ee8e0
7
+ data.tar.gz: 8979fdd5d35ee416e4c607f759b8e868188b11bb2ca7540d982866e936168170519492a027fff90cb31db12fb758b144389691c9374acfd58fd1880105d2201c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # will_paginate
2
2
 
3
- will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Merb, DataMapper and Sequel.
3
+ will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, Merb, DataMapper and Sequel.
4
4
 
5
5
  Installation:
6
6
 
@@ -16,10 +16,10 @@ See [installation instructions][install] on the wiki for more info.
16
16
 
17
17
  ``` ruby
18
18
  ## perform a paginated query:
19
- @posts = Post.paginate(:page => params[:page])
19
+ @posts = Post.paginate(page: params[:page])
20
20
 
21
21
  # or, use an explicit "per page" limit:
22
- Post.paginate(:page => params[:page], :per_page => 30)
22
+ Post.paginate(page: params[:page], per_page: 30)
23
23
 
24
24
  ## render page links in the view:
25
25
  <%= will_paginate @posts %>
@@ -49,13 +49,12 @@ Post.where(:published => true).paginate(:page => params[:page]).order('id DESC')
49
49
  Post.page(params[:page]).order('created_at DESC')
50
50
  ```
51
51
 
52
- See [the wiki][wiki] for more documentation. [Ask on the group][group] if you have usage questions. [Report bugs][issues] on GitHub.
52
+ See [the wiki][wiki] for more documentation. [Report bugs][issues] on GitHub.
53
53
 
54
54
  Happy paginating.
55
55
 
56
56
 
57
57
  [wiki]: https://github.com/mislav/will_paginate/wiki
58
58
  [install]: https://github.com/mislav/will_paginate/wiki/Installation "will_paginate installation"
59
- [group]: http://groups.google.com/group/will_paginate "will_paginate discussion and support group"
60
59
  [issues]: https://github.com/mislav/will_paginate/issues
61
60
  [css]: http://mislav.github.io/will_paginate/
@@ -83,7 +83,10 @@ module WillPaginate
83
83
  excluded = [:order, :limit, :offset, :reorder]
84
84
  excluded << :includes unless eager_loading?
85
85
  rel = self.except(*excluded)
86
- column_name = (select_for_count(rel) || :all)
86
+ column_name = if rel.select_values.present?
87
+ select = rel.select_values.join(", ")
88
+ select if select !~ /[,*]/
89
+ end || :all
87
90
  rel.count(column_name)
88
91
  else
89
92
  super(*args)
@@ -102,9 +105,7 @@ module WillPaginate
102
105
  # overloaded to be pagination-aware
103
106
  def empty?
104
107
  if !loaded? and offset_value
105
- result = count
106
- result = result.size if result.respond_to?(:size) and !result.is_a?(Integer)
107
- result <= offset_value
108
+ total_entries <= offset_value
108
109
  else
109
110
  super
110
111
  end
@@ -136,13 +137,6 @@ module WillPaginate
136
137
  other.total_entries = nil if defined? @total_entries_queried
137
138
  other
138
139
  end
139
-
140
- def select_for_count(rel)
141
- if rel.select_values.present?
142
- select = rel.select_values.join(", ")
143
- select if select !~ /[,*]/
144
- end
145
- end
146
140
  end
147
141
 
148
142
  module Pagination
@@ -216,6 +210,8 @@ module WillPaginate
216
210
  WHERE rownum <= #{pager.offset + pager.per_page}
217
211
  ) WHERE rnum >= #{pager.offset}
218
212
  SQL
213
+ elsif (self.connection.adapter_name =~ /^sqlserver/i)
214
+ query << " OFFSET #{pager.offset} ROWS FETCH NEXT #{pager.per_page} ROWS ONLY"
219
215
  else
220
216
  query << " LIMIT #{pager.per_page} OFFSET #{pager.offset}"
221
217
  end
@@ -31,8 +31,8 @@ module WillPaginate::Deprecation
31
31
  super
32
32
  end
33
33
 
34
- def deprecate_key(*keys)
35
- message = block_given? ? Proc.new : keys.pop
34
+ def deprecate_key(*keys, &block)
35
+ message = block_given? ? block : keys.pop
36
36
  Array(keys).each { |key| @deprecated[key] = message }
37
37
  end
38
38
 
@@ -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 `Fixnum === 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'
@@ -38,9 +37,15 @@ module WillPaginate
38
37
  alias_method :status_code, :status_code_with_paginate
39
38
  end
40
39
  def status_code_with_paginate(exception = @exception)
41
- if exception.is_a?(WillPaginate::InvalidPage) or
42
- (exception.respond_to?(:original_exception) &&
43
- exception.original_exception.is_a?(WillPaginate::InvalidPage))
40
+ actual_exception = if exception.respond_to?(:cause)
41
+ exception.cause || exception
42
+ elsif exception.respond_to?(:original_exception)
43
+ exception.original_exception
44
+ else
45
+ exception
46
+ end
47
+
48
+ if actual_exception.is_a?(WillPaginate::InvalidPage)
44
49
  Rack::Utils.status_code(:not_found)
45
50
  else
46
51
  original_method = method(:status_code_without_paginate)
@@ -54,11 +59,11 @@ module WillPaginate
54
59
  end
55
60
 
56
61
  module ControllerRescuePatch
57
- def rescue_from(*args, &block)
62
+ def rescue_from(*args, **kwargs, &block)
58
63
  if idx = args.index(WillPaginate::InvalidPage)
59
64
  args[idx] = args[idx].name
60
65
  end
61
- super(*args, &block)
66
+ super(*args, **kwargs, &block)
62
67
  end
63
68
  end
64
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 = 3
4
+ MINOR = 3
5
+ TINY = 0
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
@@ -24,7 +24,7 @@ module WillPaginate
24
24
  # method as you see fit.
25
25
  def to_html
26
26
  html = pagination.map do |item|
27
- item.is_a?(Fixnum) ?
27
+ item.is_a?(Integer) ?
28
28
  page_number(item) :
29
29
  send(item)
30
30
  end.join(@options[:link_separator])
@@ -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)
44
- unless page == current_page
45
- link(page, page, :rel => rel_value(page))
47
+ aria_label = @template.will_paginate_translate(:page_aria_label, :page => page.to_i) { "Page #{page}" }
48
+ if page == current_page
49
+ tag(:em, page, :class => 'current', :"aria-label" => aria_label, :"aria-current" => 'page')
46
50
  else
47
- tag(:em, page, :class => 'current')
51
+ link(page, page, :rel => rel_value(page), :"aria-label" => aria_label)
48
52
  end
49
53
  end
50
54
 
@@ -88,7 +92,7 @@ module WillPaginate
88
92
  end
89
93
 
90
94
  def link(text, target, attributes = {})
91
- if target.is_a? Fixnum
95
+ if target.is_a?(Integer)
92
96
  attributes[:rel] = rel_value(target)
93
97
  target = url(target)
94
98
  end
@@ -108,9 +112,8 @@ module WillPaginate
108
112
 
109
113
  def rel_value(page)
110
114
  case page
111
- when @collection.current_page - 1; 'prev' + (page == 1 ? ' start' : '')
115
+ when @collection.current_page - 1; 'prev'
112
116
  when @collection.current_page + 1; 'next'
113
- when 1; 'start'
114
117
  end
115
118
  end
116
119
 
@@ -30,7 +30,7 @@ module WillPaginate
30
30
  window_from = current_page - inner_window
31
31
  window_to = current_page + inner_window
32
32
 
33
- # adjust lower or upper limit if other is out of bounds
33
+ # adjust lower or upper limit if either is out of bounds
34
34
  if window_to > total_pages
35
35
  window_from -= window_to - total_pages
36
36
  window_to = total_pages
@@ -6,7 +6,7 @@ sqlite3:
6
6
  mysql: &mysql
7
7
  adapter: mysql
8
8
  database: will_paginate
9
- username:
9
+ username: root
10
10
  encoding: utf8
11
11
  <% if File.exist?("/var/run/mysql5/mysqld.sock") %>
12
12
  host: localhost
@@ -3,7 +3,6 @@ require 'will_paginate/active_record'
3
3
  require File.expand_path('../activerecord_test_connector', __FILE__)
4
4
 
5
5
  ActiverecordTestConnector.setup
6
- abort unless ActiverecordTestConnector.able_to_connect
7
6
 
8
7
  describe WillPaginate::ActiveRecord do
9
8
 
@@ -164,6 +163,13 @@ describe WillPaginate::ActiveRecord do
164
163
  topics.total_entries.should == 999
165
164
  end
166
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
+
167
173
  it "removes :include for count" do
168
174
  lambda {
169
175
  developers = Developer.paginate(:page => 1, :per_page => 1).includes(:projects)
@@ -214,7 +220,7 @@ describe WillPaginate::ActiveRecord do
214
220
  sql = "select content from topics where content like '%futurama%'"
215
221
  topics = Topic.paginate_by_sql sql, :page => 1, :per_page => 1
216
222
  topics.total_entries.should == 1
217
- topics.first.attributes.has_key?('title').should be_false
223
+ topics.first.attributes.has_key?('title').should be(false)
218
224
  }.should run_queries(2)
219
225
  end
220
226
 
@@ -272,12 +278,12 @@ describe WillPaginate::ActiveRecord do
272
278
  }.should run_queries(1)
273
279
  end
274
280
 
275
- 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
276
282
  lambda {
277
283
  result = Topic.paginate :page => 2
278
284
  result.total_pages.should == 1
279
285
  result.should be_empty
280
- }.should run_queries(2)
286
+ }.should run_queries(1)
281
287
  end
282
288
 
283
289
  describe "associations" do
@@ -38,7 +38,6 @@ end
38
38
  module ActiverecordTestConnector
39
39
  extend self
40
40
 
41
- attr_accessor :able_to_connect
42
41
  attr_accessor :connected
43
42
 
44
43
  FIXTURES_PATH = File.expand_path('../../fixtures', __FILE__)
@@ -49,18 +48,14 @@ module ActiverecordTestConnector
49
48
 
50
49
  # Set our defaults
51
50
  self.connected = false
52
- self.able_to_connect = true
53
51
 
54
52
  def setup
55
- unless self.connected || !self.able_to_connect
53
+ unless self.connected
56
54
  setup_connection
57
55
  load_schema
58
56
  add_load_path FIXTURES_PATH
59
57
  self.connected = true
60
58
  end
61
- rescue Exception => e # errors from ActiveRecord setup
62
- $stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n"
63
- self.able_to_connect = false
64
59
  end
65
60
 
66
61
  private
@@ -84,6 +79,13 @@ module ActiverecordTestConnector
84
79
  ActiveRecord::Base.configurations = { db => configuration }
85
80
  ActiveRecord::Base.establish_connection(db.to_sym)
86
81
  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
87
89
  end
88
90
 
89
91
  def load_schema
@@ -95,7 +97,13 @@ module ActiverecordTestConnector
95
97
  $stdout = STDOUT
96
98
  end
97
99
  end
98
-
100
+
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
+
99
107
  module FixtureSetup
100
108
  def fixtures(*tables)
101
109
  table_names = tables.map { |t| t.to_s }
@@ -1,13 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- begin
3
+ if !ENV['SKIP_NONRAILS_TESTS']
4
4
  require 'will_paginate/data_mapper'
5
5
  require File.expand_path('../data_mapper_test_connector', __FILE__)
6
- rescue LoadError => error
7
- warn "Error running DataMapper specs: #{error.message}"
8
- datamapper_loaded = false
9
- else
10
6
  datamapper_loaded = true
7
+ else
8
+ datamapper_loaded = false
11
9
  end
12
10
 
13
11
  describe WillPaginate::DataMapper do
@@ -1,18 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
- begin
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
4
10
  require 'will_paginate/mongoid'
5
- rescue LoadError => error
6
- warn "Error running Mongoid specs: #{error.message}"
7
- mongoid_loaded = false
8
- else
9
- Mongoid.connect_to 'will_paginate_test'
11
+ Object.send(:const_set, :Rails, old_rails) if old_rails
10
12
 
13
+ Mongo::Logger.logger.level = Logger::INFO
14
+
15
+ Mongoid.connect_to 'will_paginate_test'
11
16
  class MongoidModel
12
17
  include Mongoid::Document
13
18
  end
14
19
 
15
20
  mongoid_loaded = true
21
+ else
22
+ mongoid_loaded = false
16
23
  end
17
24
 
18
25
  describe WillPaginate::Mongoid do
@@ -1,26 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
- begin
3
+ if !ENV['SKIP_NONRAILS_TESTS']
4
4
  require 'will_paginate/sequel'
5
5
  require File.expand_path('../sequel_test_connector', __FILE__)
6
- rescue LoadError, ArgumentError => error
7
- warn "Error running Sequel specs: #{error.message}"
8
- sequel_loaded = false
9
- else
10
6
  sequel_loaded = true
7
+ else
8
+ sequel_loaded = false
11
9
  end
12
10
 
13
11
  describe Sequel::Dataset::Pagination, 'extension' do
14
12
 
15
13
  class Car < Sequel::Model
14
+ self.dataset = dataset.extension(:pagination)
16
15
  end
17
16
 
18
17
  it "should have the #paginate method" do
19
- Car.should respond_to(:paginate)
18
+ Car.dataset.should respond_to(:paginate)
20
19
  end
21
20
 
22
21
  it "should NOT have the #paginate_by_sql method" do
23
- Car.should_not respond_to(:paginate_by_sql)
22
+ Car.dataset.should_not respond_to(:paginate_by_sql)
24
23
  end
25
24
 
26
25
  describe 'pagination' do
@@ -31,7 +30,7 @@ describe Sequel::Dataset::Pagination, 'extension' do
31
30
  end
32
31
 
33
32
  it "should imitate WillPaginate::Collection" do
34
- result = Car.paginate(1, 2)
33
+ result = Car.dataset.paginate(1, 2)
35
34
 
36
35
  result.should_not be_empty
37
36
  result.size.should == 2
@@ -43,16 +42,16 @@ describe Sequel::Dataset::Pagination, 'extension' do
43
42
  end
44
43
 
45
44
  it "should perform" do
46
- Car.paginate(1, 2).all.should == [Car[1], Car[2]]
45
+ Car.dataset.paginate(1, 2).all.should == [Car[1], Car[2]]
47
46
  end
48
47
 
49
48
  it "should be empty" do
50
- result = Car.paginate(3, 2)
49
+ result = Car.dataset.paginate(3, 2)
51
50
  result.should be_empty
52
51
  end
53
52
 
54
53
  it "should perform with #select and #order" do
55
- result = Car.select("name as foo".lit).order(:name).paginate(1, 2).all
54
+ result = Car.select(Sequel.lit("name as foo")).order(:name).paginate(1, 2).all
56
55
  result.size.should == 2
57
56
  result.first.values[:foo].should == "Aston Martin"
58
57
  end
@@ -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
@@ -23,12 +24,12 @@ describe WillPaginate::PageNumber do
23
24
  (num.is_a? Numeric).should be
24
25
  end
25
26
 
26
- it "is a kind of Fixnum" do
27
- (num.is_a? Fixnum).should be
27
+ it "is a kind of Integer" do
28
+ (num.is_a? Integer).should be
28
29
  end
29
30
 
30
- it "isn't directly a Fixnum" do
31
- (num.instance_of? Fixnum).should_not be
31
+ it "isn't directly a Integer" do
32
+ (num.instance_of? Integer).should_not be
32
33
  end
33
34
 
34
35
  it "passes the PageNumber=== type check" do |variable|
@@ -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
- (Fixnum === 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
 
@@ -42,5 +42,5 @@ RSpec.configure do |config|
42
42
  }
43
43
 
44
44
  config.mock_with :mocha
45
- config.backtrace_clean_patterns << /view_example_group/
45
+ config.backtrace_exclusion_patterns << /view_example_group/
46
46
  end
@@ -14,7 +14,8 @@ Routes.draw do
14
14
  get 'ibocorp(/:page)' => 'ibocorp#index',
15
15
  :constraints => { :page => /\d+/ }, :defaults => { :page => 1 }
16
16
 
17
- get ':controller(/:action(/:id(.:format)))'
17
+ get 'foo/bar' => 'foo#bar'
18
+ get 'baz/list' => 'baz#list'
18
19
  end
19
20
 
20
21
  describe WillPaginate::ActionView do
@@ -38,7 +39,14 @@ describe WillPaginate::ActionView do
38
39
  attr_reader :assigns, :controller, :request
39
40
 
40
41
  def render(locals)
41
- @view = ActionView::Base.new([], @assigns, @controller)
42
+ lookup_context = []
43
+ if defined? ActionView::LookupContext
44
+ lookup_context = ActionView::LookupContext.new(lookup_context)
45
+ end
46
+
47
+ klass = ActionView::Base
48
+ klass = klass.with_empty_template_cache if klass.respond_to?(:with_empty_template_cache)
49
+ @view = klass.new(lookup_context, @assigns, @controller)
42
50
  @view.request = @request
43
51
  @view.singleton_class.send(:include, @controller._routes.url_helpers)
44
52
  @view.render(:inline => @template, :locals => locals)
@@ -80,9 +88,9 @@ describe WillPaginate::ActionView do
80
88
  validate_page_numbers [1,1,3,3], elements
81
89
  # test rel attribute values:
82
90
  text(elements[0]).should == 'Prev'
83
- elements[0]['rel'].should == 'prev start'
91
+ elements[0]['rel'].should == 'prev'
84
92
  text(elements[1]).should == '1'
85
- elements[1]['rel'].should == 'prev start'
93
+ elements[1]['rel'].should == 'prev'
86
94
  text(elements[3]).should == 'Next'
87
95
  elements[3]['rel'].should == 'next'
88
96
  end
@@ -120,16 +128,20 @@ describe WillPaginate::ActionView do
120
128
  it "should match expected markup" do
121
129
  paginate
122
130
  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>
131
+ <div class="pagination" role="navigation" aria-label="Pagination"><span class="previous_page disabled">&#8592; Previous</span>
132
+ <em class="current" aria-label="Page 1" aria-current="page">1</em>
133
+ <a href="/foo/bar?page=2" aria-label="Page 2" rel="next">2</a>
134
+ <a href="/foo/bar?page=3" aria-label="Page 3">3</a>
127
135
  <a href="/foo/bar?page=2" class="next_page" rel="next">Next &#8594;</a></div>
128
136
  HTML
129
137
  expected.strip!.gsub!(/\s{2,}/, ' ')
130
- expected_dom = parse_html_document(expected).root
138
+ expected_dom = parse_html_document(expected)
131
139
 
132
- html_document.root.should == expected_dom
140
+ if expected_dom.respond_to?(:canonicalize)
141
+ html_document.canonicalize.should == expected_dom.canonicalize
142
+ else
143
+ html_document.root.should == expected_dom.root
144
+ end
133
145
  end
134
146
 
135
147
  it "should output escaped URLs" do
@@ -50,7 +50,7 @@ module ViewExampleGroup
50
50
  end
51
51
 
52
52
  def parse_html_document(html)
53
- @html_document ||= if defined?(Rails::Dom::Testing::Assertions)
53
+ if defined?(Rails::Dom::Testing::Assertions)
54
54
  Nokogiri::HTML::Document.parse(html)
55
55
  else
56
56
  HTML::Document.new(html, true, false)
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.3
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mislav Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-21 00:00:00.000000000 Z
11
+ date: 2020-02-26 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
@@ -77,10 +78,15 @@ files:
77
78
  - spec/view_helpers/base_spec.rb
78
79
  - spec/view_helpers/link_renderer_base_spec.rb
79
80
  - spec/view_helpers/view_example_group.rb
80
- homepage: https://github.com/mislav/will_paginate/wiki
81
+ homepage: https://github.com/mislav/will_paginate
81
82
  licenses:
82
83
  - MIT
83
- metadata: {}
84
+ metadata:
85
+ bug_tracker_uri: https://github.com/mislav/will_paginate/issues
86
+ changelog_uri: https://github.com/mislav/will_paginate/releases/tag/v3.3.0
87
+ documentation_uri: https://www.rubydoc.info/gems/will_paginate/3.3.0
88
+ source_code_uri: https://github.com/mislav/will_paginate/tree/v3.3.0
89
+ wiki_uri: https://github.com/mislav/will_paginate/wiki
84
90
  post_install_message:
85
91
  rdoc_options:
86
92
  - "--main"
@@ -92,15 +98,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
98
  requirements:
93
99
  - - ">="
94
100
  - !ruby/object:Gem::Version
95
- version: '0'
101
+ version: '2.0'
96
102
  required_rubygems_version: !ruby/object:Gem::Requirement
97
103
  requirements:
98
104
  - - ">="
99
105
  - !ruby/object:Gem::Version
100
106
  version: '0'
101
107
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.5.1
108
+ rubygems_version: 3.1.2
104
109
  signing_key:
105
110
  specification_version: 4
106
111
  summary: Pagination plugin for web frameworks and other apps