will_paginate 3.3.0 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/lib/will_paginate/version.rb +1 -1
- data/lib/will_paginate/view_helpers/link_renderer.rb +1 -1
- data/spec/database.yml +11 -11
- data/spec/finders/activerecord_test_connector.rb +7 -40
- data/spec/spec_helper.rb +0 -5
- data/spec/view_helpers/action_view_spec.rb +15 -14
- data/spec/view_helpers/view_example_group.rb +5 -46
- metadata +9 -15
- data/spec/fake_rubygems.rb +0 -18
- data/spec/finders/data_mapper_spec.rb +0 -114
- data/spec/finders/data_mapper_test_connector.rb +0 -54
- data/spec/finders/mongoid_spec.rb +0 -147
- data/spec/finders/sequel_spec.rb +0 -66
- data/spec/finders/sequel_test_connector.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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
@@ -2,15 +2,13 @@
|
|
2
2
|
|
3
3
|
will_paginate is a pagination library that integrates with Ruby on Rails, Sinatra, Hanami::View, Merb, DataMapper and Sequel.
|
4
4
|
|
5
|
-
Installation:
|
6
|
-
|
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
|
|
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: root
|
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"] %>
|
@@ -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 =
|
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
|
-
|
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 |*
|
91
|
+
define_method(table_name) do |*names|
|
125
92
|
@@fixture_cache[table_name] ||= {}
|
126
93
|
|
127
|
-
instances =
|
128
|
-
if @@loaded_fixtures[table_name][
|
129
|
-
@@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
|
130
97
|
else
|
131
|
-
raise StandardError, "No fixture with name '#{
|
98
|
+
raise StandardError, "No fixture with name '#{name}' found for table '#{table_name}'"
|
132
99
|
end
|
133
100
|
end
|
134
101
|
|
data/spec/spec_helper.rb
CHANGED
@@ -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'
|
@@ -23,6 +22,8 @@ describe WillPaginate::ActionView do
|
|
23
22
|
before(:all) do
|
24
23
|
I18n.load_path.concat WillPaginate::I18n.load_path
|
25
24
|
I18n.enforce_available_locales = false
|
25
|
+
|
26
|
+
ActionController::Parameters.permit_all_parameters = false
|
26
27
|
end
|
27
28
|
|
28
29
|
before(:each) do
|
@@ -40,9 +41,7 @@ describe WillPaginate::ActionView do
|
|
40
41
|
|
41
42
|
def render(locals)
|
42
43
|
lookup_context = []
|
43
|
-
|
44
|
-
lookup_context = ActionView::LookupContext.new(lookup_context)
|
45
|
-
end
|
44
|
+
lookup_context = ActionView::LookupContext.new(lookup_context)
|
46
45
|
|
47
46
|
klass = ActionView::Base
|
48
47
|
klass = klass.with_empty_template_cache if klass.respond_to?(:with_empty_template_cache)
|
@@ -128,7 +127,7 @@ describe WillPaginate::ActionView do
|
|
128
127
|
it "should match expected markup" do
|
129
128
|
paginate
|
130
129
|
expected = <<-HTML
|
131
|
-
<div class="pagination" role="navigation" aria-label="Pagination"><span class="previous_page disabled">← Previous</span>
|
130
|
+
<div class="pagination" role="navigation" aria-label="Pagination"><span class="previous_page disabled" aria-disabled="true">← Previous</span>
|
132
131
|
<em class="current" aria-label="Page 1" aria-current="page">1</em>
|
133
132
|
<a href="/foo/bar?page=2" aria-label="Page 2" rel="next">2</a>
|
134
133
|
<a href="/foo/bar?page=3" aria-label="Page 3">3</a>
|
@@ -370,6 +369,16 @@ describe WillPaginate::ActionView do
|
|
370
369
|
end
|
371
370
|
end
|
372
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
|
+
|
373
382
|
private
|
374
383
|
|
375
384
|
def translation(data)
|
@@ -454,11 +463,7 @@ class DummyRequest
|
|
454
463
|
|
455
464
|
def params(more = nil)
|
456
465
|
@params.update(more) if more
|
457
|
-
|
458
|
-
ActionController::Parameters.new(@params)
|
459
|
-
else
|
460
|
-
@params
|
461
|
-
end
|
466
|
+
ActionController::Parameters.new(@params)
|
462
467
|
end
|
463
468
|
|
464
469
|
def host_with_port
|
@@ -474,7 +479,3 @@ class DummyRequest
|
|
474
479
|
'http:'
|
475
480
|
end
|
476
481
|
end
|
477
|
-
|
478
|
-
if defined?(ActionController::Parameters)
|
479
|
-
ActionController::Parameters.permit_all_parameters = false
|
480
|
-
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: will_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
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
|
@@ -48,14 +48,8 @@ files:
|
|
48
48
|
- spec/console
|
49
49
|
- spec/console_fixtures.rb
|
50
50
|
- spec/database.yml
|
51
|
-
- spec/fake_rubygems.rb
|
52
51
|
- spec/finders/active_record_spec.rb
|
53
52
|
- spec/finders/activerecord_test_connector.rb
|
54
|
-
- spec/finders/data_mapper_spec.rb
|
55
|
-
- spec/finders/data_mapper_test_connector.rb
|
56
|
-
- spec/finders/mongoid_spec.rb
|
57
|
-
- spec/finders/sequel_spec.rb
|
58
|
-
- spec/finders/sequel_test_connector.rb
|
59
53
|
- spec/fixtures/admin.rb
|
60
54
|
- spec/fixtures/developer.rb
|
61
55
|
- spec/fixtures/developers_projects.yml
|
@@ -83,11 +77,11 @@ licenses:
|
|
83
77
|
- MIT
|
84
78
|
metadata:
|
85
79
|
bug_tracker_uri: https://github.com/mislav/will_paginate/issues
|
86
|
-
changelog_uri: https://github.com/mislav/will_paginate/releases/tag/v3.3.
|
87
|
-
documentation_uri: https://www.rubydoc.info/gems/will_paginate/3.3.
|
88
|
-
source_code_uri: https://github.com/mislav/will_paginate/tree/v3.3.
|
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
|
89
83
|
wiki_uri: https://github.com/mislav/will_paginate/wiki
|
90
|
-
post_install_message:
|
84
|
+
post_install_message:
|
91
85
|
rdoc_options:
|
92
86
|
- "--main"
|
93
87
|
- README.md
|
@@ -105,8 +99,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
99
|
- !ruby/object:Gem::Version
|
106
100
|
version: '0'
|
107
101
|
requirements: []
|
108
|
-
rubygems_version: 3.1.
|
109
|
-
signing_key:
|
102
|
+
rubygems_version: 3.1.4
|
103
|
+
signing_key:
|
110
104
|
specification_version: 4
|
111
105
|
summary: Pagination plugin for web frameworks and other apps
|
112
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,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,147 +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
|
-
Mongo::Logger.logger.level = Logger::INFO
|
14
|
-
|
15
|
-
Mongoid.connect_to 'will_paginate_test'
|
16
|
-
class MongoidModel
|
17
|
-
include Mongoid::Document
|
18
|
-
end
|
19
|
-
|
20
|
-
mongoid_loaded = true
|
21
|
-
else
|
22
|
-
mongoid_loaded = false
|
23
|
-
end
|
24
|
-
|
25
|
-
describe WillPaginate::Mongoid do
|
26
|
-
before(:all) do
|
27
|
-
MongoidModel.delete_all
|
28
|
-
4.times { MongoidModel.create! }
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:criteria) { MongoidModel.criteria }
|
32
|
-
|
33
|
-
describe "#page" do
|
34
|
-
it "should forward to the paginate method" do
|
35
|
-
criteria.expects(:paginate).with(:page => 2).returns("itself")
|
36
|
-
criteria.page(2).should == "itself"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should not override per_page if set earlier in the chain" do
|
40
|
-
criteria.paginate(:per_page => 10).page(1).per_page.should == 10
|
41
|
-
criteria.paginate(:per_page => 20).page(1).per_page.should == 20
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#per_page" do
|
46
|
-
it "should set the limit if given an argument" do
|
47
|
-
criteria.per_page(10).options[:limit].should == 10
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should return the current limit if no argument is given" do
|
51
|
-
criteria.per_page.should == nil
|
52
|
-
criteria.per_page(10).per_page.should == 10
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should be interchangable with limit" do
|
56
|
-
criteria.limit(15).per_page.should == 15
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should be nil'able" do
|
60
|
-
criteria.per_page(nil).per_page.should be_nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "#paginate" do
|
65
|
-
it "should use criteria" do
|
66
|
-
criteria.paginate.should be_instance_of(::Mongoid::Criteria)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should not override page number if set earlier in the chain" do
|
70
|
-
criteria.page(3).paginate.current_page.should == 3
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should limit according to per_page parameter" do
|
74
|
-
criteria.paginate(:per_page => 10).options.should include(:limit => 10)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should skip according to page and per_page parameters" do
|
78
|
-
criteria.paginate(:page => 2, :per_page => 5).options.should include(:skip => 5)
|
79
|
-
end
|
80
|
-
|
81
|
-
specify "first fallback value for per_page option is the current limit" do
|
82
|
-
criteria.limit(12).paginate.options.should include(:limit => 12)
|
83
|
-
end
|
84
|
-
|
85
|
-
specify "second fallback value for per_page option is WillPaginate.per_page" do
|
86
|
-
criteria.paginate.options.should include(:limit => WillPaginate.per_page)
|
87
|
-
end
|
88
|
-
|
89
|
-
specify "page should default to 1" do
|
90
|
-
criteria.paginate.options.should include(:skip => 0)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should convert strings to integers" do
|
94
|
-
criteria.paginate(:page => "2", :per_page => "3").options.should include(:limit => 3)
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "collection compatibility" do
|
98
|
-
describe "#total_count" do
|
99
|
-
it "should be calculated correctly" do
|
100
|
-
criteria.paginate(:per_page => 1).total_entries.should == 4
|
101
|
-
criteria.paginate(:per_page => 3).total_entries.should == 4
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should be cached" do
|
105
|
-
criteria.expects(:count).once.returns(123)
|
106
|
-
criteria.paginate
|
107
|
-
2.times { criteria.total_entries.should == 123 }
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should calculate total_pages" do
|
112
|
-
criteria.paginate(:per_page => 1).total_pages.should == 4
|
113
|
-
criteria.paginate(:per_page => 3).total_pages.should == 2
|
114
|
-
criteria.paginate(:per_page => 10).total_pages.should == 1
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should return per_page" do
|
118
|
-
criteria.paginate(:per_page => 1).per_page.should == 1
|
119
|
-
criteria.paginate(:per_page => 5).per_page.should == 5
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "#current_page" do
|
123
|
-
it "should return current_page" do
|
124
|
-
criteria.paginate(:page => 1).current_page.should == 1
|
125
|
-
criteria.paginate(:page => 3).current_page.should == 3
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should be casted to PageNumber" do
|
129
|
-
page = criteria.paginate(:page => 1).current_page
|
130
|
-
(page.instance_of? WillPaginate::PageNumber).should be
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should return offset" do
|
135
|
-
criteria.paginate(:page => 1).offset.should == 0
|
136
|
-
criteria.paginate(:page => 2, :per_page => 5).offset.should == 5
|
137
|
-
criteria.paginate(:page => 3, :per_page => 10).offset.should == 20
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should not pollute plain mongoid criterias" do
|
141
|
-
%w(total_entries total_pages current_page).each do |method|
|
142
|
-
criteria.should_not respond_to(method)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end if mongoid_loaded
|
data/spec/finders/sequel_spec.rb
DELETED
@@ -1,66 +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
|
-
self.dataset = dataset.extension(:pagination)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should have the #paginate method" do
|
18
|
-
Car.dataset.should respond_to(:paginate)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should NOT have the #paginate_by_sql method" do
|
22
|
-
Car.dataset.should_not respond_to(:paginate_by_sql)
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'pagination' do
|
26
|
-
before(:all) do
|
27
|
-
Car.create(:name => 'Shelby', :notes => "Man's best friend")
|
28
|
-
Car.create(:name => 'Aston Martin', :notes => "Woman's best friend")
|
29
|
-
Car.create(:name => 'Corvette', :notes => 'King of the Jungle')
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should imitate WillPaginate::Collection" do
|
33
|
-
result = Car.dataset.paginate(1, 2)
|
34
|
-
|
35
|
-
result.should_not be_empty
|
36
|
-
result.size.should == 2
|
37
|
-
result.length.should == 2
|
38
|
-
result.total_entries.should == 3
|
39
|
-
result.total_pages.should == 2
|
40
|
-
result.per_page.should == 2
|
41
|
-
result.current_page.should == 1
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should perform" do
|
45
|
-
Car.dataset.paginate(1, 2).all.should == [Car[1], Car[2]]
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should be empty" do
|
49
|
-
result = Car.dataset.paginate(3, 2)
|
50
|
-
result.should be_empty
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should perform with #select and #order" do
|
54
|
-
result = Car.select(Sequel.lit("name as foo")).order(:name).paginate(1, 2).all
|
55
|
-
result.size.should == 2
|
56
|
-
result.first.values[:foo].should == "Aston Martin"
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should perform with #filter" do
|
60
|
-
results = Car.filter(:name => 'Shelby').paginate(1, 2).all
|
61
|
-
results.size.should == 1
|
62
|
-
results.first.should == Car.find(:name => 'Shelby')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
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
|