will_paginate 3.1.5 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +5 -8
- data/lib/will_paginate/active_record.rb +7 -11
- data/lib/will_paginate/deprecation.rb +2 -2
- data/lib/will_paginate/i18n.rb +3 -3
- data/lib/will_paginate/locale/en.yml +2 -0
- data/lib/will_paginate/mongoid.rb +2 -0
- data/lib/will_paginate/page_number.rb +7 -11
- data/lib/will_paginate/railtie.rb +3 -4
- data/lib/will_paginate/version.rb +2 -2
- data/lib/will_paginate/view_helpers/action_view.rb +2 -2
- data/lib/will_paginate/view_helpers/hanami.rb +41 -0
- data/lib/will_paginate/view_helpers/link_renderer.rb +10 -6
- data/spec/database.yml +11 -11
- data/spec/finders/active_record_spec.rb +10 -4
- data/spec/finders/activerecord_test_connector.rb +9 -34
- data/spec/page_number_spec.rb +13 -5
- data/spec/spec_helper.rb +1 -6
- data/spec/view_helpers/action_view_spec.rb +31 -18
- data/spec/view_helpers/view_example_group.rb +5 -46
- metadata +16 -17
- data/spec/fake_rubygems.rb +0 -18
- data/spec/finders/data_mapper_spec.rb +0 -116
- data/spec/finders/data_mapper_test_connector.rb +0 -54
- data/spec/finders/mongoid_spec.rb +0 -140
- data/spec/finders/sequel_spec.rb +0 -67
- data/spec/finders/sequel_test_connector.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3015c2c4a4d84d48b8a9c60a5ad19297e4ccbd515682df95399badb293386536
|
4
|
+
data.tar.gz: d28dd41a8fe68e9f5e43649978cb8a49b8ff03fc6fcdab303c04fcbe654a6894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6c6843a2f26883a439520ef4106124c1706c8f5deae59c16d1fee074d74a8eb50e39ef3ea8ae8dc0bd6a18331dd618c0f18079f3834b0ebda45a13f050d3f62
|
7
|
+
data.tar.gz: 5479f100b92648394d8074d2d34be19120008955ce5f5e289073eafac35389890f044d4a66fe0e54d5331fc7d6a82c17497fa800f4fee44c743939560a71af8c
|
data/README.md
CHANGED
@@ -1,25 +1,23 @@
|
|
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
|
|
17
15
|
``` ruby
|
18
16
|
## perform a paginated query:
|
19
|
-
@posts = Post.paginate(:
|
17
|
+
@posts = Post.paginate(page: params[:page])
|
20
18
|
|
21
19
|
# or, use an explicit "per page" limit:
|
22
|
-
Post.paginate(:
|
20
|
+
Post.paginate(page: params[:page], per_page: 30)
|
23
21
|
|
24
22
|
## render page links in the view:
|
25
23
|
<%= will_paginate @posts %>
|
@@ -49,13 +47,12 @@ Post.where(:published => true).paginate(:page => params[:page]).order('id DESC')
|
|
49
47
|
Post.page(params[:page]).order('created_at DESC')
|
50
48
|
```
|
51
49
|
|
52
|
-
See [the wiki][wiki] for more documentation. [
|
50
|
+
See [the wiki][wiki] for more documentation. [Report bugs][issues] on GitHub.
|
53
51
|
|
54
52
|
Happy paginating.
|
55
53
|
|
56
54
|
|
57
55
|
[wiki]: https://github.com/mislav/will_paginate/wiki
|
58
56
|
[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
57
|
[issues]: https://github.com/mislav/will_paginate/issues
|
61
58
|
[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 =
|
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
|
-
|
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? ?
|
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
|
|
data/lib/will_paginate/i18n.rb
CHANGED
@@ -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 <<
|
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
|
@@ -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 <
|
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
|
-
|
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
|
-
|
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'
|
@@ -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
|
@@ -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
|
-
#
|
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?(
|
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 ||=
|
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
|
|
@@ -88,7 +92,7 @@ module WillPaginate
|
|
88
92
|
end
|
89
93
|
|
90
94
|
def link(text, target, attributes = {})
|
91
|
-
if target.is_a?
|
95
|
+
if target.is_a?(Integer)
|
92
96
|
attributes[:rel] = rel_value(target)
|
93
97
|
target = url(target)
|
94
98
|
end
|
data/spec/database.yml
CHANGED
@@ -3,27 +3,27 @@ sqlite3:
|
|
3
3
|
adapter: sqlite3
|
4
4
|
timeout: 500
|
5
5
|
|
6
|
-
mysql:
|
7
|
-
adapter:
|
6
|
+
mysql:
|
7
|
+
adapter: mysql2
|
8
8
|
database: will_paginate
|
9
|
-
username:
|
9
|
+
username: <%= ENV["MYSQL_USER"] || "root" %>
|
10
10
|
encoding: utf8
|
11
|
-
<% if
|
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"] %>
|
@@ -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
|
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
|
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(
|
286
|
+
}.should run_queries(1)
|
281
287
|
end
|
282
288
|
|
283
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
|
|
@@ -38,29 +26,20 @@ end
|
|
38
26
|
module ActiverecordTestConnector
|
39
27
|
extend self
|
40
28
|
|
41
|
-
attr_accessor :able_to_connect
|
42
29
|
attr_accessor :connected
|
43
30
|
|
44
31
|
FIXTURES_PATH = File.expand_path('../../fixtures', __FILE__)
|
45
32
|
|
46
|
-
Fixtures = defined?(ActiveRecord::FixtureSet) ? ActiveRecord::FixtureSet :
|
47
|
-
defined?(ActiveRecord::Fixtures) ? ActiveRecord::Fixtures :
|
48
|
-
::Fixtures
|
49
|
-
|
50
33
|
# Set our defaults
|
51
34
|
self.connected = false
|
52
|
-
self.able_to_connect = true
|
53
35
|
|
54
36
|
def setup
|
55
|
-
unless self.connected
|
37
|
+
unless self.connected
|
56
38
|
setup_connection
|
57
39
|
load_schema
|
58
40
|
add_load_path FIXTURES_PATH
|
59
41
|
self.connected = true
|
60
42
|
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
43
|
end
|
65
44
|
|
66
45
|
private
|
@@ -95,32 +74,28 @@ module ActiverecordTestConnector
|
|
95
74
|
$stdout = STDOUT
|
96
75
|
end
|
97
76
|
end
|
98
|
-
|
77
|
+
|
99
78
|
module FixtureSetup
|
100
79
|
def fixtures(*tables)
|
101
80
|
table_names = tables.map { |t| t.to_s }
|
102
81
|
|
103
|
-
fixtures =
|
82
|
+
fixtures = ActiveRecord::FixtureSet.create_fixtures(ActiverecordTestConnector::FIXTURES_PATH, table_names)
|
104
83
|
@@loaded_fixtures = {}
|
105
84
|
@@fixture_cache = {}
|
106
85
|
|
107
86
|
unless fixtures.nil?
|
108
|
-
|
109
|
-
@@loaded_fixtures[fixtures.table_name] = fixtures
|
110
|
-
else
|
111
|
-
fixtures.each { |f| @@loaded_fixtures[f.table_name] = f }
|
112
|
-
end
|
87
|
+
fixtures.each { |f| @@loaded_fixtures[f.table_name] = f }
|
113
88
|
end
|
114
89
|
|
115
90
|
table_names.each do |table_name|
|
116
|
-
define_method(table_name) do |*
|
91
|
+
define_method(table_name) do |*names|
|
117
92
|
@@fixture_cache[table_name] ||= {}
|
118
93
|
|
119
|
-
instances =
|
120
|
-
if @@loaded_fixtures[table_name][
|
121
|
-
@@fixture_cache[table_name][
|
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
|
122
97
|
else
|
123
|
-
raise StandardError, "No fixture with name '#{
|
98
|
+
raise StandardError, "No fixture with name '#{name}' found for table '#{table_name}'"
|
124
99
|
end
|
125
100
|
end
|
126
101
|
|
data/spec/page_number_spec.rb
CHANGED
@@ -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
|
27
|
-
(num.is_a?
|
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
|
31
|
-
(num.instance_of?
|
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
|
-
|
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.
|
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 '
|
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
|
-
|
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">← 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">← 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 →</a></div>
|
128
135
|
HTML
|
129
136
|
expected.strip!.gsub!(/\s{2,}/, ' ')
|
130
|
-
expected_dom = parse_html_document(expected)
|
137
|
+
expected_dom = parse_html_document(expected)
|
131
138
|
|
132
|
-
|
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
|
-
|
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
|
-
|
4
|
-
|
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
|
-
|
23
|
-
|
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
|
-
|
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
|
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:
|
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
|
75
|
+
homepage: https://github.com/mislav/will_paginate
|
81
76
|
licenses:
|
82
77
|
- MIT
|
83
|
-
metadata:
|
84
|
-
|
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
|
-
|
103
|
-
|
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: []
|
data/spec/fake_rubygems.rb
DELETED
@@ -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,116 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'will_paginate/data_mapper'
|
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
|
-
datamapper_loaded = true
|
11
|
-
end
|
12
|
-
|
13
|
-
describe WillPaginate::DataMapper do
|
14
|
-
|
15
|
-
it "has per_page" do
|
16
|
-
Animal.per_page.should == 30
|
17
|
-
begin
|
18
|
-
Animal.per_page = 10
|
19
|
-
Animal.per_page.should == 10
|
20
|
-
|
21
|
-
subclass = Class.new(Animal)
|
22
|
-
subclass.per_page.should == 10
|
23
|
-
ensure
|
24
|
-
Animal.per_page = 30
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it "doesn't make normal collections appear paginated" do
|
29
|
-
Animal.all.should_not be_paginated
|
30
|
-
end
|
31
|
-
|
32
|
-
it "paginates to first page by default" do
|
33
|
-
animals = Animal.paginate(:page => nil)
|
34
|
-
|
35
|
-
animals.should be_paginated
|
36
|
-
animals.current_page.should == 1
|
37
|
-
animals.per_page.should == 30
|
38
|
-
animals.offset.should == 0
|
39
|
-
animals.total_entries.should == 3
|
40
|
-
animals.total_pages.should == 1
|
41
|
-
end
|
42
|
-
|
43
|
-
it "paginates to first page, explicit limit" do
|
44
|
-
animals = Animal.paginate(:page => 1, :per_page => 2)
|
45
|
-
|
46
|
-
animals.current_page.should == 1
|
47
|
-
animals.per_page.should == 2
|
48
|
-
animals.total_entries.should == 3
|
49
|
-
animals.total_pages.should == 2
|
50
|
-
animals.map {|a| a.name }.should == %w[ Dog Cat ]
|
51
|
-
end
|
52
|
-
|
53
|
-
it "paginates to second page" do
|
54
|
-
animals = Animal.paginate(:page => 2, :per_page => 2)
|
55
|
-
|
56
|
-
animals.current_page.should == 2
|
57
|
-
animals.offset.should == 2
|
58
|
-
animals.map {|a| a.name }.should == %w[ Lion ]
|
59
|
-
end
|
60
|
-
|
61
|
-
it "paginates a collection" do
|
62
|
-
friends = Animal.all(:notes.like => '%friend%')
|
63
|
-
friends.paginate(:page => 1).per_page.should == 30
|
64
|
-
friends.paginate(:page => 1, :per_page => 1).total_entries.should == 2
|
65
|
-
end
|
66
|
-
|
67
|
-
it "paginates a limited collection" do
|
68
|
-
animals = Animal.all(:limit => 2).paginate(:page => 1)
|
69
|
-
animals.per_page.should == 2
|
70
|
-
end
|
71
|
-
|
72
|
-
it "has page() method" do
|
73
|
-
Animal.page(2).per_page.should == 30
|
74
|
-
Animal.page(2).offset.should == 30
|
75
|
-
Animal.page(2).current_page.should == 2
|
76
|
-
Animal.all(:limit => 2).page(2).per_page.should == 2
|
77
|
-
end
|
78
|
-
|
79
|
-
it "has total_pages at 1 for empty collections" do
|
80
|
-
Animal.all(:conditions => ['1=2']).page(1).total_pages.should == 1
|
81
|
-
end
|
82
|
-
|
83
|
-
it "overrides total_entries count with a fixed value" do
|
84
|
-
lambda {
|
85
|
-
animals = Animal.paginate :page => 1, :per_page => 3, :total_entries => 999
|
86
|
-
animals.total_entries.should == 999
|
87
|
-
}.should run_queries(0)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "supports a non-int for total_entries" do
|
91
|
-
topics = Animal.paginate :page => 1, :per_page => 3, :total_entries => "999"
|
92
|
-
topics.total_entries.should == 999
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
it "can iterate and then call WP methods" do
|
97
|
-
animals = Animal.all(:limit => 2).page(1)
|
98
|
-
animals.each { |a| }
|
99
|
-
animals.total_entries.should == 3
|
100
|
-
end
|
101
|
-
|
102
|
-
it "augments to_a to return a WP::Collection" do
|
103
|
-
animals = Animal.all(:limit => 2).page(1)
|
104
|
-
array = animals.to_a
|
105
|
-
array.size.should == 2
|
106
|
-
array.should be_kind_of(WillPaginate::Collection)
|
107
|
-
array.current_page.should == 1
|
108
|
-
array.per_page.should == 2
|
109
|
-
end
|
110
|
-
|
111
|
-
it "doesn't have a problem assigning has-one-through relationship" do
|
112
|
-
human = Human.create :name => "Mislav"
|
113
|
-
human.pet = Animal.first
|
114
|
-
end
|
115
|
-
|
116
|
-
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,140 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
begin
|
4
|
-
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'
|
10
|
-
|
11
|
-
class MongoidModel
|
12
|
-
include Mongoid::Document
|
13
|
-
end
|
14
|
-
|
15
|
-
mongoid_loaded = true
|
16
|
-
end
|
17
|
-
|
18
|
-
describe WillPaginate::Mongoid do
|
19
|
-
before(:all) do
|
20
|
-
MongoidModel.delete_all
|
21
|
-
4.times { MongoidModel.create! }
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:criteria) { MongoidModel.criteria }
|
25
|
-
|
26
|
-
describe "#page" do
|
27
|
-
it "should forward to the paginate method" do
|
28
|
-
criteria.expects(:paginate).with(:page => 2).returns("itself")
|
29
|
-
criteria.page(2).should == "itself"
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should not override per_page if set earlier in the chain" do
|
33
|
-
criteria.paginate(:per_page => 10).page(1).per_page.should == 10
|
34
|
-
criteria.paginate(:per_page => 20).page(1).per_page.should == 20
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#per_page" do
|
39
|
-
it "should set the limit if given an argument" do
|
40
|
-
criteria.per_page(10).options[:limit].should == 10
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return the current limit if no argument is given" do
|
44
|
-
criteria.per_page.should == nil
|
45
|
-
criteria.per_page(10).per_page.should == 10
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should be interchangable with limit" do
|
49
|
-
criteria.limit(15).per_page.should == 15
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should be nil'able" do
|
53
|
-
criteria.per_page(nil).per_page.should be_nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "#paginate" do
|
58
|
-
it "should use criteria" do
|
59
|
-
criteria.paginate.should be_instance_of(::Mongoid::Criteria)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not override page number if set earlier in the chain" do
|
63
|
-
criteria.page(3).paginate.current_page.should == 3
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should limit according to per_page parameter" do
|
67
|
-
criteria.paginate(:per_page => 10).options.should include(:limit => 10)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should skip according to page and per_page parameters" do
|
71
|
-
criteria.paginate(:page => 2, :per_page => 5).options.should include(:skip => 5)
|
72
|
-
end
|
73
|
-
|
74
|
-
specify "first fallback value for per_page option is the current limit" do
|
75
|
-
criteria.limit(12).paginate.options.should include(:limit => 12)
|
76
|
-
end
|
77
|
-
|
78
|
-
specify "second fallback value for per_page option is WillPaginate.per_page" do
|
79
|
-
criteria.paginate.options.should include(:limit => WillPaginate.per_page)
|
80
|
-
end
|
81
|
-
|
82
|
-
specify "page should default to 1" do
|
83
|
-
criteria.paginate.options.should include(:skip => 0)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should convert strings to integers" do
|
87
|
-
criteria.paginate(:page => "2", :per_page => "3").options.should include(:limit => 3)
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "collection compatibility" do
|
91
|
-
describe "#total_count" do
|
92
|
-
it "should be calculated correctly" do
|
93
|
-
criteria.paginate(:per_page => 1).total_entries.should == 4
|
94
|
-
criteria.paginate(:per_page => 3).total_entries.should == 4
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should be cached" do
|
98
|
-
criteria.expects(:count).once.returns(123)
|
99
|
-
criteria.paginate
|
100
|
-
2.times { criteria.total_entries.should == 123 }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should calculate total_pages" do
|
105
|
-
criteria.paginate(:per_page => 1).total_pages.should == 4
|
106
|
-
criteria.paginate(:per_page => 3).total_pages.should == 2
|
107
|
-
criteria.paginate(:per_page => 10).total_pages.should == 1
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should return per_page" do
|
111
|
-
criteria.paginate(:per_page => 1).per_page.should == 1
|
112
|
-
criteria.paginate(:per_page => 5).per_page.should == 5
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "#current_page" do
|
116
|
-
it "should return current_page" do
|
117
|
-
criteria.paginate(:page => 1).current_page.should == 1
|
118
|
-
criteria.paginate(:page => 3).current_page.should == 3
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should be casted to PageNumber" do
|
122
|
-
page = criteria.paginate(:page => 1).current_page
|
123
|
-
(page.instance_of? WillPaginate::PageNumber).should be
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should return offset" do
|
128
|
-
criteria.paginate(:page => 1).offset.should == 0
|
129
|
-
criteria.paginate(:page => 2, :per_page => 5).offset.should == 5
|
130
|
-
criteria.paginate(:page => 3, :per_page => 10).offset.should == 20
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should not pollute plain mongoid criterias" do
|
134
|
-
%w(total_entries total_pages current_page).each do |method|
|
135
|
-
criteria.should_not respond_to(method)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end if mongoid_loaded
|
data/spec/finders/sequel_spec.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'will_paginate/sequel'
|
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
|
-
sequel_loaded = true
|
11
|
-
end
|
12
|
-
|
13
|
-
describe Sequel::Dataset::Pagination, 'extension' do
|
14
|
-
|
15
|
-
class Car < Sequel::Model
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should have the #paginate method" do
|
19
|
-
Car.should respond_to(:paginate)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should NOT have the #paginate_by_sql method" do
|
23
|
-
Car.should_not respond_to(:paginate_by_sql)
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'pagination' do
|
27
|
-
before(:all) do
|
28
|
-
Car.create(:name => 'Shelby', :notes => "Man's best friend")
|
29
|
-
Car.create(:name => 'Aston Martin', :notes => "Woman's best friend")
|
30
|
-
Car.create(:name => 'Corvette', :notes => 'King of the Jungle')
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should imitate WillPaginate::Collection" do
|
34
|
-
result = Car.paginate(1, 2)
|
35
|
-
|
36
|
-
result.should_not be_empty
|
37
|
-
result.size.should == 2
|
38
|
-
result.length.should == 2
|
39
|
-
result.total_entries.should == 3
|
40
|
-
result.total_pages.should == 2
|
41
|
-
result.per_page.should == 2
|
42
|
-
result.current_page.should == 1
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should perform" do
|
46
|
-
Car.paginate(1, 2).all.should == [Car[1], Car[2]]
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should be empty" do
|
50
|
-
result = Car.paginate(3, 2)
|
51
|
-
result.should be_empty
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should perform with #select and #order" do
|
55
|
-
result = Car.select("name as foo".lit).order(:name).paginate(1, 2).all
|
56
|
-
result.size.should == 2
|
57
|
-
result.first.values[:foo].should == "Aston Martin"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should perform with #filter" do
|
61
|
-
results = Car.filter(:name => 'Shelby').paginate(1, 2).all
|
62
|
-
results.size.should == 1
|
63
|
-
results.first.should == Car.find(:name => 'Shelby')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
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
|