paginate 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -9
- data/README.md +5 -6
- data/Rakefile +9 -4
- data/gemfiles/{rails_3_2.gemfile → rails_5_0.gemfile} +1 -1
- data/lib/paginate/active_record.rb +10 -6
- data/lib/paginate/version.rb +1 -1
- data/paginate.gemspec +5 -2
- data/{spec/paginate/action_view_spec.rb → test/paginate/actionview_test.rb} +10 -7
- data/test/paginate/activerecord_test.rb +30 -0
- data/test/paginate/base_test.rb +72 -0
- data/test/paginate/configuration_test.rb +35 -0
- data/test/paginate/renderer/base_test.rb +53 -0
- data/test/paginate/renderer/list_test.rb +109 -0
- data/test/paginate/renderer/more_test.rb +39 -0
- data/{spec → test}/schema.rb +0 -0
- data/{spec → test}/support/controller.rb +0 -0
- data/test/support/matchers.rb +11 -0
- data/{spec → test}/support/model.rb +0 -0
- data/{spec → test}/support/translations.yml +0 -0
- data/{spec → test}/support/views/application/_block_as_url.erb +0 -0
- data/{spec → test}/support/views/application/_default.erb +0 -0
- data/test/support/views/application/_number.erb +1 -0
- data/test/support/views/application/_render.erb +1 -0
- data/{spec/spec_helper.rb → test/test_helper.rb} +12 -6
- metadata +72 -47
- data/.rspec +0 -1
- data/gemfiles/rails_4_0.gemfile +0 -4
- data/gemfiles/rails_4_1.gemfile +0 -4
- data/spec/paginate/activerecord_spec.rb +0 -24
- data/spec/paginate/base_spec.rb +0 -70
- data/spec/paginate/configuration_spec.rb +0 -35
- data/spec/paginate/renderer/base_spec.rb +0 -53
- data/spec/paginate/renderer/list_spec.rb +0 -111
- data/spec/paginate/renderer/more_spec.rb +0 -38
- data/spec/support/matchers.rb +0 -11
- data/spec/support/views/application/_number.erb +0 -1
- data/spec/support/views/application/_render.erb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d39513796c1b20a4495f9f50e95fbe768961891
|
4
|
+
data.tar.gz: 332610509ba0407a179cb6700186f8f373673547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66d0c3ae7596f90f280dbfcc38b33fed8d8af3e50f5429937b23775ddc4bb6bbced35a8232327cb79330f4462f469651a493adf0ce81cc4132e3f12640d721b8
|
7
|
+
data.tar.gz: aecad0c6aacb0751590f6cb1f5311bb2e17f4acf03553f4bdcc4b3fd26b042ce683971fe6da80cc25aec838d9bffbb12c9a276f850e1de4916a7f0eb380b0c12
|
data/.travis.yml
CHANGED
@@ -2,15 +2,14 @@ sudo: false
|
|
2
2
|
cache: bundler
|
3
3
|
language: ruby
|
4
4
|
rvm:
|
5
|
-
- '2.0'
|
6
|
-
- '2.1'
|
7
|
-
- '2.2'
|
8
|
-
|
5
|
+
- '2.3.0'
|
9
6
|
gemfile:
|
10
|
-
- gemfiles/rails_3_2.gemfile
|
11
|
-
- gemfiles/rails_4_0.gemfile
|
12
|
-
- gemfiles/rails_4_1.gemfile
|
13
7
|
- gemfiles/rails_4_2.gemfile
|
8
|
+
- gemfiles/rails_5_0.gemfile
|
14
9
|
- Gemfile
|
15
|
-
|
16
|
-
|
10
|
+
script: bundle exec rake
|
11
|
+
notifications:
|
12
|
+
email: false
|
13
|
+
env:
|
14
|
+
global:
|
15
|
+
secure: u2w8v0Fwk5ieq+3wWsPZfNpE57oWgeJexeo0/R0kZGzuUjkLtxhG/onvNRirW+8spVP8onAtsN5BqVfAyVp0rPwwRGjPrBNeYLkVQB9+RnXtwbuCxzKtNOqegtvg43YcGbBjlN4Aai0Xjf0rA+avc7OQ3C4ZFbhLgUyIAn9hTeE=
|
data/README.md
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/fnando/paginate.png)](https://travis-ci.org/fnando/paginate)
|
4
4
|
[![CodeClimate](https://codeclimate.com/github/fnando/paginate.png)](https://codeclimate.com/github/fnando/paginate/)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/fnando/paginate/badges/coverage.svg)](https://codeclimate.com/github/fnando/paginate/coverage)
|
6
|
+
[![Gem](https://img.shields.io/gem/v/paginate.svg)](https://rubygems.org/gems/paginate)
|
7
|
+
[![Gem](https://img.shields.io/gem/dt/paginate.svg)](https://rubygems.org/gems/paginate)
|
5
8
|
|
6
9
|
Paginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support.
|
7
10
|
|
8
|
-
Works only with **Rails 3+**.
|
9
|
-
|
10
11
|
## Install
|
11
12
|
|
12
13
|
```bash
|
@@ -72,7 +73,7 @@ en:
|
|
72
73
|
paginate:
|
73
74
|
next: "Older"
|
74
75
|
previous: "Newer"
|
75
|
-
page: "Page {
|
76
|
+
page: "Page %{page}"
|
76
77
|
more: "Load more"
|
77
78
|
```
|
78
79
|
|
@@ -135,9 +136,7 @@ You can also specify while calling the `paginate` helper.
|
|
135
136
|
|
136
137
|
(The MIT License)
|
137
138
|
|
138
|
-
Copyright
|
139
|
-
|
140
|
-
* Nando Vieira • <http://simplesideias.com.br>
|
139
|
+
Copyright - Nando Vieira • <http://nandovieira.com>
|
141
140
|
|
142
141
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
143
142
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
require "bundler"
|
2
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
7
|
+
t.warning = false
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: :test
|
@@ -1,12 +1,16 @@
|
|
1
|
+
module Paginate
|
2
|
+
module ActiveRecordExt
|
3
|
+
def inherited(subclass)
|
4
|
+
super(subclass)
|
5
|
+
subclass.send(:include, Paginate::Extension) if subclass.superclass == ::ActiveRecord::Base
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
1
10
|
module ActiveRecord
|
2
11
|
class Base
|
3
12
|
class << self
|
4
|
-
|
5
|
-
inherited_without_paginate subclass
|
6
|
-
subclass.send(:include, Paginate::Extension) if subclass.superclass == ActiveRecord::Base
|
7
|
-
end
|
8
|
-
|
9
|
-
alias_method_chain :inherited, :paginate
|
13
|
+
prepend Paginate::ActiveRecordExt
|
10
14
|
end
|
11
15
|
|
12
16
|
# Extend existing models
|
data/lib/paginate/version.rb
CHANGED
data/paginate.gemspec
CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.homepage = "http://rubygems.org/gems/paginate"
|
10
10
|
s.summary = "Paginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support."
|
11
11
|
s.description = s.summary
|
12
|
+
s.required_ruby_version = ">= 2.0.0"
|
12
13
|
|
13
14
|
s.files = `git ls-files`.split("\n")
|
14
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -16,9 +17,11 @@ Gem::Specification.new do |s|
|
|
16
17
|
s.require_paths = ["lib"]
|
17
18
|
|
18
19
|
s.add_development_dependency "nokogiri"
|
19
|
-
s.add_development_dependency "test_notifier"
|
20
20
|
s.add_development_dependency "sqlite3-ruby"
|
21
21
|
s.add_development_dependency "rails"
|
22
|
-
s.add_development_dependency "
|
22
|
+
s.add_development_dependency "minitest", "~> 5.1"
|
23
|
+
s.add_development_dependency "minitest-utils"
|
23
24
|
s.add_development_dependency "pry-meta"
|
25
|
+
s.add_development_dependency "mocha"
|
26
|
+
s.add_development_dependency "codeclimate-test-reporter"
|
24
27
|
end
|
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
require "spec_helper"
|
1
|
+
require "test_helper"
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
class ActionviewTest < Minitest::Test
|
4
|
+
setup do
|
6
5
|
@request = OpenStruct.new
|
7
6
|
@params = Hash.new
|
8
7
|
|
@@ -15,7 +14,7 @@ describe "ActionView support" do
|
|
15
14
|
@view.lookup_context.prefixes << "application"
|
16
15
|
@view.controller = @controller
|
17
16
|
@view.extend(Paginate::Helper)
|
18
|
-
|
17
|
+
@view.stubs(:request).returns(@request)
|
19
18
|
|
20
19
|
@helper = Object.new
|
21
20
|
@helper.extend(Paginate::Helper)
|
@@ -28,19 +27,23 @@ describe "ActionView support" do
|
|
28
27
|
I18n.locale = :en
|
29
28
|
end
|
30
29
|
|
31
|
-
|
30
|
+
test "overrides render method" do
|
32
31
|
items = [*1..11].map do |i|
|
33
32
|
OpenStruct.new(:to_partial_path => "number", :value => i)
|
34
33
|
end
|
35
34
|
|
36
35
|
html = render(:render, items)
|
36
|
+
|
37
|
+
assert 10, html.css("p.number").size
|
38
|
+
assert_equal ("1".."10").to_a, html.css("p.number").map(&:text)
|
37
39
|
end
|
38
40
|
|
39
41
|
private
|
42
|
+
|
40
43
|
def render(view_name, items)
|
41
44
|
@controller.params = @params
|
42
45
|
view_info = Struct.new(:to_partial_path).new("#{view_name}")
|
43
|
-
Nokogiri
|
46
|
+
Nokogiri::HTML(@view.render(view_info, items: items))
|
44
47
|
end
|
45
48
|
|
46
49
|
def load_view(name)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ActiverecordTest < Minitest::Test
|
4
|
+
let(:things) { Array.new(15) {|i| Thing.create!(name: "THING") } }
|
5
|
+
|
6
|
+
setup do
|
7
|
+
things
|
8
|
+
Paginate.configuration.size = 10
|
9
|
+
end
|
10
|
+
|
11
|
+
test "responds to paginate" do
|
12
|
+
assert Thing.respond_to?(:paginate)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "uses default options" do
|
16
|
+
items = Thing.limit(11).to_a
|
17
|
+
assert_equal items, Thing.paginate.to_a
|
18
|
+
|
19
|
+
items = Thing.limit(11).offset(10).to_a
|
20
|
+
assert_equal items, Thing.paginate(page: 2).to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
test "uses custom options" do
|
24
|
+
items = Thing.limit(6).to_a
|
25
|
+
assert_equal items, Thing.paginate(size: 5).to_a
|
26
|
+
|
27
|
+
items = Thing.limit(6).offset(5).to_a
|
28
|
+
assert_equal items, Thing.paginate(size: 5, page: 2).to_a
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BaseTest < Minitest::Test
|
4
|
+
let(:scope) { mock }
|
5
|
+
|
6
|
+
test "returns page from integer" do
|
7
|
+
assert_equal 12, Paginate::Base.new(scope, 12).page
|
8
|
+
end
|
9
|
+
|
10
|
+
test "returns page from string" do
|
11
|
+
assert_equal 12, Paginate::Base.new(scope, "12").page
|
12
|
+
end
|
13
|
+
|
14
|
+
test "defaults to page 1" do
|
15
|
+
assert_equal 1, Paginate::Base.new(scope).page
|
16
|
+
end
|
17
|
+
|
18
|
+
test "returns page from options" do
|
19
|
+
assert_equal 12, Paginate::Base.new(scope, page: 12).page
|
20
|
+
end
|
21
|
+
|
22
|
+
test "returns limtest from configuration" do
|
23
|
+
Paginate.configuration.size = 25
|
24
|
+
assert_equal 26, Paginate::Base.new(scope).limit
|
25
|
+
end
|
26
|
+
|
27
|
+
test "returns limtest from options" do
|
28
|
+
Paginate.configuration.size = 25
|
29
|
+
assert_equal 14, Paginate::Base.new(scope, size: 13).limit
|
30
|
+
end
|
31
|
+
|
32
|
+
test "returns default limit" do
|
33
|
+
Paginate.configuration.size = nil
|
34
|
+
assert_equal 11, Paginate::Base.new(scope).limit
|
35
|
+
end
|
36
|
+
|
37
|
+
test "returns offset from configuration" do
|
38
|
+
Paginate.configuration.size = 15
|
39
|
+
assert_equal 15, Paginate::Base.new(scope, page: 2).offset
|
40
|
+
end
|
41
|
+
|
42
|
+
test "returns offset from options" do
|
43
|
+
assert_equal 5, Paginate::Base.new(scope, page: 2, size: 5).offset
|
44
|
+
end
|
45
|
+
|
46
|
+
test "returns finder options" do
|
47
|
+
actual = Paginate::Base.new(scope, page: 3, size: 5).to_options
|
48
|
+
expected = {limit: 6, offset: 10}
|
49
|
+
|
50
|
+
assert_equal expected, actual
|
51
|
+
end
|
52
|
+
|
53
|
+
test "has next page" do
|
54
|
+
paginate = Paginate::Base.new(scope, page: 1, size: 5, collection: Array.new(6))
|
55
|
+
assert paginate.next_page?
|
56
|
+
end
|
57
|
+
|
58
|
+
test "doesn't have next page" do
|
59
|
+
paginate = Paginate::Base.new(scope, page: 1, size: 5, collection: Array.new(5))
|
60
|
+
refute paginate.next_page?
|
61
|
+
end
|
62
|
+
|
63
|
+
test "has previous page" do
|
64
|
+
paginate = Paginate::Base.new(scope, page: 2)
|
65
|
+
assert paginate.previous_page?
|
66
|
+
end
|
67
|
+
|
68
|
+
test "doesn't have previous page" do
|
69
|
+
paginate = Paginate::Base.new(scope, page: 1)
|
70
|
+
refute paginate.previous_page?
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ConfigurationTest < Minitest::Test
|
4
|
+
test "sets default configuration" do
|
5
|
+
assert_equal :page, Paginate.configuration.param_name
|
6
|
+
assert_equal Paginate::Renderer::List, Paginate.configuration.renderer
|
7
|
+
assert_equal 10, Paginate.configuration.size
|
8
|
+
end
|
9
|
+
|
10
|
+
test "yields configuration class" do
|
11
|
+
Paginate.configure do |config|
|
12
|
+
config.param_name = :p
|
13
|
+
config.size = 50
|
14
|
+
end
|
15
|
+
|
16
|
+
assert_equal :p, Paginate.configuration.param_name
|
17
|
+
assert_equal 50, Paginate.configuration.size
|
18
|
+
end
|
19
|
+
|
20
|
+
test "returns configuration as hash" do
|
21
|
+
Paginate.configure do |config|
|
22
|
+
config.param_name = :p
|
23
|
+
config.size = 25
|
24
|
+
config.renderer = Paginate::Renderer::List
|
25
|
+
end
|
26
|
+
|
27
|
+
options = {
|
28
|
+
param_name: :p,
|
29
|
+
size: 25,
|
30
|
+
renderer: Paginate::Renderer::List
|
31
|
+
}
|
32
|
+
|
33
|
+
assert_equal options, Paginate.configuration.to_hash
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BaseTest < Minitest::Test
|
4
|
+
setup do
|
5
|
+
Paginate.configure do |config|
|
6
|
+
config.param_name = :page
|
7
|
+
config.size = 10
|
8
|
+
end
|
9
|
+
|
10
|
+
I18n.locale = :en
|
11
|
+
|
12
|
+
@renderer = Paginate::Renderer::Base.new(nil, {
|
13
|
+
collection: Array.new(11),
|
14
|
+
page: 1,
|
15
|
+
fullpath: "/some/path"
|
16
|
+
})
|
17
|
+
end
|
18
|
+
|
19
|
+
test "parses simple url" do
|
20
|
+
@renderer.options[:url] = "/some/path"
|
21
|
+
assert_equal "/some/path?page=1", @renderer.url_for(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
test "parses url with page param" do
|
25
|
+
@renderer.options[:url] = "/some/path?page=3"
|
26
|
+
assert_equal "/some/path?page=1", @renderer.url_for(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
test "parses url with page as first param" do
|
30
|
+
@renderer.options[:url] = "/some/path?page=3&a=1&b=2&c=3"
|
31
|
+
assert_equal "/some/path?a=1&b=2&c=3&page=1", @renderer.url_for(1)
|
32
|
+
end
|
33
|
+
|
34
|
+
test "parses url with page as last param" do
|
35
|
+
@renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=3"
|
36
|
+
assert_equal "/some/path?a=1&b=2&c=3&page=1", @renderer.url_for(1)
|
37
|
+
end
|
38
|
+
|
39
|
+
test "parses url with page param in the middle" do
|
40
|
+
@renderer.options[:url] = "/some/path?a=1&b=2&page=3&c=3"
|
41
|
+
assert_equal "/some/path?a=1&b=2&c=3&page=1", @renderer.url_for(1)
|
42
|
+
end
|
43
|
+
|
44
|
+
test "parses url with page as arbitrary string" do
|
45
|
+
@renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=abc"
|
46
|
+
assert_equal "/some/path?a=1&b=2&c=3&page=1", @renderer.url_for(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
test "escapes url from blocks" do
|
50
|
+
@renderer.options[:url] = proc {|page| "/some/path/#{page}?a=1&b=2"}
|
51
|
+
assert_equal "/some/path/1?a=1&b=2", @renderer.url_for(1)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BaseTest < Minitest::Test
|
4
|
+
setup do
|
5
|
+
Paginate.configure do |config|
|
6
|
+
config.param_name = :page
|
7
|
+
config.size = 10
|
8
|
+
end
|
9
|
+
|
10
|
+
I18n.locale = :en
|
11
|
+
|
12
|
+
@renderer = Paginate::Renderer::List.new(nil, {
|
13
|
+
collection: Array.new(11),
|
14
|
+
page: 1,
|
15
|
+
fullpath: "/some/path"
|
16
|
+
})
|
17
|
+
end
|
18
|
+
|
19
|
+
test "returns safe html" do
|
20
|
+
assert @renderer.render.html_safe?
|
21
|
+
end
|
22
|
+
|
23
|
+
test "returns labels" do
|
24
|
+
assert_equal I18n.t("paginate.previous"), @renderer.previous_label
|
25
|
+
assert_equal I18n.t("paginate.next"), @renderer.next_label
|
26
|
+
assert_equal I18n.t("paginate.page", page: 1), @renderer.page_label
|
27
|
+
end
|
28
|
+
|
29
|
+
test "displays current page" do
|
30
|
+
@renderer.processor.stubs(page: 1234)
|
31
|
+
|
32
|
+
html = Nokogiri::HTML(@renderer.render)
|
33
|
+
span = html.css("li.page > span").first
|
34
|
+
|
35
|
+
assert span
|
36
|
+
assert_equal "Page 1234", span.text
|
37
|
+
end
|
38
|
+
|
39
|
+
test "translates strings" do
|
40
|
+
I18n.locale = "pt-BR"
|
41
|
+
@renderer.processor.stubs(page: 10)
|
42
|
+
|
43
|
+
html = Nokogiri::HTML(@renderer.render)
|
44
|
+
|
45
|
+
assert_equal "Página 10", html.css("li.page > span").text
|
46
|
+
assert_equal "Próxima página", html.css("li.next-page > a").text
|
47
|
+
assert_equal "Página anterior", html.css("li.previous-page > a").text
|
48
|
+
end
|
49
|
+
|
50
|
+
test "displays previous page link" do
|
51
|
+
@renderer.processor.stubs(page: 2)
|
52
|
+
|
53
|
+
html = Nokogiri::HTML(@renderer.render)
|
54
|
+
link = html.css("li.previous-page > a").first
|
55
|
+
|
56
|
+
assert link
|
57
|
+
assert_equal "/some/path?page=1", link["href"]
|
58
|
+
assert_equal "Previous page", link.text
|
59
|
+
end
|
60
|
+
|
61
|
+
test "displays next page link" do
|
62
|
+
@renderer.processor.stubs(page: 1)
|
63
|
+
|
64
|
+
html = Nokogiri::HTML(@renderer.render)
|
65
|
+
link = html.css("li.next-page > a").first
|
66
|
+
|
67
|
+
assert link
|
68
|
+
assert_equal "/some/path?page=2", link["href"]
|
69
|
+
assert_equal "Next page", link.text
|
70
|
+
end
|
71
|
+
|
72
|
+
test "displays pagination list" do
|
73
|
+
html = Nokogiri::HTML(@renderer.render)
|
74
|
+
|
75
|
+
assert_equal 1, html.css("ul.paginate").count
|
76
|
+
assert_equal 3, html.css("ul.paginate > li").count
|
77
|
+
end
|
78
|
+
|
79
|
+
test "adds .disabled class to the list when have no items" do
|
80
|
+
@renderer.processor.stubs(next_page?: false, previous_page?: false)
|
81
|
+
|
82
|
+
html = Nokogiri::HTML(@renderer.render)
|
83
|
+
assert html.css("ul.paginate.disabled").first
|
84
|
+
end
|
85
|
+
|
86
|
+
test "disables element when have no next page" do
|
87
|
+
@renderer.processor.stubs(next_page?: false)
|
88
|
+
|
89
|
+
html = Nokogiri::HTML(@renderer.render)
|
90
|
+
link = html.css("li.next-page > a").first
|
91
|
+
span = html.css("li.next-page.disabled > span").first
|
92
|
+
|
93
|
+
assert span
|
94
|
+
refute link
|
95
|
+
assert_equal "Next page", span.text
|
96
|
+
end
|
97
|
+
|
98
|
+
test "disables element when have no previous page" do
|
99
|
+
@renderer.processor.stubs(previous_page?: false)
|
100
|
+
|
101
|
+
html = Nokogiri::HTML(@renderer.render)
|
102
|
+
link = html.css("li.previous-page > a").first
|
103
|
+
span = html.css("li.previous-page.disabled > span").first
|
104
|
+
|
105
|
+
assert span
|
106
|
+
refute link
|
107
|
+
assert_equal "Previous page", span.text
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class MoreTest < Minitest::Test
|
4
|
+
setup do
|
5
|
+
Paginate.configure do |config|
|
6
|
+
config.param_name = :page
|
7
|
+
config.size = 10
|
8
|
+
end
|
9
|
+
|
10
|
+
I18n.locale = :en
|
11
|
+
|
12
|
+
@renderer = Paginate::Renderer::More.new(nil, {
|
13
|
+
collection: Array.new(11),
|
14
|
+
page: 1,
|
15
|
+
fullpath: "/some/path"
|
16
|
+
})
|
17
|
+
end
|
18
|
+
|
19
|
+
test "returns safe html" do
|
20
|
+
assert @renderer.render.html_safe?
|
21
|
+
end
|
22
|
+
|
23
|
+
test "returns label" do
|
24
|
+
assert_equal I18n.t("paginate.more"), @renderer.more_label
|
25
|
+
end
|
26
|
+
|
27
|
+
test "returns nothing when have no next page" do
|
28
|
+
@renderer.processor.stubs(next_page?: false)
|
29
|
+
assert_nil @renderer.render
|
30
|
+
end
|
31
|
+
|
32
|
+
test "returns html when have next page" do
|
33
|
+
html = Nokogiri::HTML(@renderer.render)
|
34
|
+
selector = "p.paginate > a.more"
|
35
|
+
|
36
|
+
assert_equal @renderer.more_label, html.css(selector).text
|
37
|
+
assert_equal @renderer.next_url, html.css(selector).first[:href]
|
38
|
+
end
|
39
|
+
end
|
data/{spec → test}/schema.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<p class="number"><%= number.value %></p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render items, paginate: true %>
|
@@ -1,12 +1,16 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
1
4
|
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
|
2
5
|
require "bundler/setup"
|
3
6
|
|
7
|
+
require "minitest/utils"
|
8
|
+
require "minitest/autorun"
|
9
|
+
|
4
10
|
require "logger"
|
5
|
-
require "rspec"
|
6
11
|
require "nokogiri"
|
7
12
|
require "ostruct"
|
8
13
|
require "sqlite3"
|
9
|
-
require "test_notifier/runner/rspec"
|
10
14
|
require "rails"
|
11
15
|
|
12
16
|
require "active_record"
|
@@ -20,13 +24,15 @@ ActiveRecord::Base.establish_connection(
|
|
20
24
|
database: ":memory:"
|
21
25
|
)
|
22
26
|
|
23
|
-
load "
|
27
|
+
load "test/schema.rb"
|
24
28
|
|
25
29
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|file| require file}
|
26
30
|
I18n.load_path << File.dirname(__FILE__) + "/support/translations.yml"
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
32
|
+
module Minitest
|
33
|
+
class Test
|
34
|
+
setup do
|
35
|
+
Paginate.configuration = Paginate::Configuration.new
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: sqlite3-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,21 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-utils
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
@@ -67,7 +81,7 @@ dependencies:
|
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: pry-meta
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
@@ -81,7 +95,21 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: mocha
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: codeclimate-test-reporter
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - ">="
|
@@ -103,15 +131,12 @@ extensions: []
|
|
103
131
|
extra_rdoc_files: []
|
104
132
|
files:
|
105
133
|
- ".gitignore"
|
106
|
-
- ".rspec"
|
107
134
|
- ".travis.yml"
|
108
135
|
- Gemfile
|
109
136
|
- README.md
|
110
137
|
- Rakefile
|
111
|
-
- gemfiles/rails_3_2.gemfile
|
112
|
-
- gemfiles/rails_4_0.gemfile
|
113
|
-
- gemfiles/rails_4_1.gemfile
|
114
138
|
- gemfiles/rails_4_2.gemfile
|
139
|
+
- gemfiles/rails_5_0.gemfile
|
115
140
|
- lib/paginate.rb
|
116
141
|
- lib/paginate/action_controller.rb
|
117
142
|
- lib/paginate/active_record.rb
|
@@ -125,23 +150,23 @@ files:
|
|
125
150
|
- lib/paginate/renderer/more.rb
|
126
151
|
- lib/paginate/version.rb
|
127
152
|
- paginate.gemspec
|
128
|
-
-
|
129
|
-
-
|
130
|
-
-
|
131
|
-
-
|
132
|
-
-
|
133
|
-
-
|
134
|
-
-
|
135
|
-
-
|
136
|
-
-
|
137
|
-
-
|
138
|
-
-
|
139
|
-
-
|
140
|
-
-
|
141
|
-
-
|
142
|
-
-
|
143
|
-
-
|
144
|
-
-
|
153
|
+
- test/paginate/actionview_test.rb
|
154
|
+
- test/paginate/activerecord_test.rb
|
155
|
+
- test/paginate/base_test.rb
|
156
|
+
- test/paginate/configuration_test.rb
|
157
|
+
- test/paginate/renderer/base_test.rb
|
158
|
+
- test/paginate/renderer/list_test.rb
|
159
|
+
- test/paginate/renderer/more_test.rb
|
160
|
+
- test/schema.rb
|
161
|
+
- test/support/controller.rb
|
162
|
+
- test/support/matchers.rb
|
163
|
+
- test/support/model.rb
|
164
|
+
- test/support/translations.yml
|
165
|
+
- test/support/views/application/_block_as_url.erb
|
166
|
+
- test/support/views/application/_default.erb
|
167
|
+
- test/support/views/application/_number.erb
|
168
|
+
- test/support/views/application/_render.erb
|
169
|
+
- test/test_helper.rb
|
145
170
|
homepage: http://rubygems.org/gems/paginate
|
146
171
|
licenses: []
|
147
172
|
metadata: {}
|
@@ -153,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
178
|
requirements:
|
154
179
|
- - ">="
|
155
180
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
181
|
+
version: 2.0.0
|
157
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
183
|
requirements:
|
159
184
|
- - ">="
|
@@ -161,26 +186,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
186
|
version: '0'
|
162
187
|
requirements: []
|
163
188
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.5.1
|
165
190
|
signing_key:
|
166
191
|
specification_version: 4
|
167
192
|
summary: Paginate collections using SIZE+1 to determine if there is a next page. Includes
|
168
193
|
ActiveRecord and ActionView support.
|
169
194
|
test_files:
|
170
|
-
-
|
171
|
-
-
|
172
|
-
-
|
173
|
-
-
|
174
|
-
-
|
175
|
-
-
|
176
|
-
-
|
177
|
-
-
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
182
|
-
-
|
183
|
-
-
|
184
|
-
-
|
185
|
-
-
|
186
|
-
-
|
195
|
+
- test/paginate/actionview_test.rb
|
196
|
+
- test/paginate/activerecord_test.rb
|
197
|
+
- test/paginate/base_test.rb
|
198
|
+
- test/paginate/configuration_test.rb
|
199
|
+
- test/paginate/renderer/base_test.rb
|
200
|
+
- test/paginate/renderer/list_test.rb
|
201
|
+
- test/paginate/renderer/more_test.rb
|
202
|
+
- test/schema.rb
|
203
|
+
- test/support/controller.rb
|
204
|
+
- test/support/matchers.rb
|
205
|
+
- test/support/model.rb
|
206
|
+
- test/support/translations.yml
|
207
|
+
- test/support/views/application/_block_as_url.erb
|
208
|
+
- test/support/views/application/_default.erb
|
209
|
+
- test/support/views/application/_number.erb
|
210
|
+
- test/support/views/application/_render.erb
|
211
|
+
- test/test_helper.rb
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/gemfiles/rails_4_0.gemfile
DELETED
data/gemfiles/rails_4_1.gemfile
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Thing do
|
4
|
-
let!(:things) { Array.new(15) {|i| Thing.create!(name: "THING") } }
|
5
|
-
before { Paginate.configuration.size = 10 }
|
6
|
-
|
7
|
-
it { expect(Thing).to respond_to(:paginate) }
|
8
|
-
|
9
|
-
it "uses default options" do
|
10
|
-
items = Thing.limit(11).to_a
|
11
|
-
expect(Thing.paginate.to_a).to eql(items)
|
12
|
-
|
13
|
-
items = Thing.limit(11).offset(10).to_a
|
14
|
-
expect(Thing.paginate(page: 2).to_a).to eql(items)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "uses custom options" do
|
18
|
-
items = Thing.limit(6).to_a
|
19
|
-
expect(Thing.paginate(size: 5).to_a).to eql(items)
|
20
|
-
|
21
|
-
items = Thing.limit(6).offset(5).to_a
|
22
|
-
expect(Thing.paginate(size: 5, page: 2).to_a).to eql(items)
|
23
|
-
end
|
24
|
-
end
|
data/spec/paginate/base_spec.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Paginate::Base do
|
4
|
-
let(:scope) { double }
|
5
|
-
|
6
|
-
it "returns page from integer" do
|
7
|
-
expect(Paginate::Base.new(scope, 12).page).to eql(12)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "returns page from string" do
|
11
|
-
expect(Paginate::Base.new(scope, "12").page).to eql(12)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "defaults to page 1" do
|
15
|
-
expect(Paginate::Base.new(scope).page).to eql(1)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "returns page from options" do
|
19
|
-
expect(Paginate::Base.new(scope, page: 12).page).to eql(12)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns limit from configuration" do
|
23
|
-
Paginate.configuration.size = 25
|
24
|
-
expect(Paginate::Base.new(scope).limit).to eql(26)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns limit from options" do
|
28
|
-
Paginate.configuration.size = 25
|
29
|
-
expect(Paginate::Base.new(scope, size: 13).limit).to eql(14)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "returns default limit" do
|
33
|
-
Paginate.configuration.size = nil
|
34
|
-
expect(Paginate::Base.new(scope).limit).to eql(11)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "returns offset from configuration" do
|
38
|
-
Paginate.configuration.size = 15
|
39
|
-
expect(Paginate::Base.new(scope, page: 2).offset).to eql(15)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns offset from options" do
|
43
|
-
expect(Paginate::Base.new(scope, page: 2, size: 5).offset).to eql(5)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "returns finder options" do
|
47
|
-
actual = Paginate::Base.new(scope, page: 3, size: 5).to_options
|
48
|
-
expected = {limit: 6, offset: 10}
|
49
|
-
|
50
|
-
expect(actual).to eql(expected)
|
51
|
-
end
|
52
|
-
|
53
|
-
specify {
|
54
|
-
expect(Paginate::Base.new(scope, page: 1, size: 5, collection: Array.new(6)))
|
55
|
-
.to have_next_page
|
56
|
-
}
|
57
|
-
|
58
|
-
specify {
|
59
|
-
expect(Paginate::Base.new(scope, page: 1, size: 5, collection: Array.new(5)))
|
60
|
-
.not_to have_next_page
|
61
|
-
}
|
62
|
-
|
63
|
-
specify {
|
64
|
-
expect(Paginate::Base.new(scope, page: 2)).to have_previous_page
|
65
|
-
}
|
66
|
-
|
67
|
-
specify {
|
68
|
-
expect(Paginate::Base.new(scope, page: 1)).not_to have_previous_page
|
69
|
-
}
|
70
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Paginate::Configuration do
|
4
|
-
context "sets default configuration" do
|
5
|
-
it { expect(Paginate.configuration.param_name).to eql(:page) }
|
6
|
-
it { expect(Paginate.configuration.renderer).to eql(Paginate::Renderer::List) }
|
7
|
-
it { expect(Paginate.configuration.size).to eql(10) }
|
8
|
-
end
|
9
|
-
|
10
|
-
it "yields configuration class" do
|
11
|
-
Paginate.configure do |config|
|
12
|
-
config.param_name = :p
|
13
|
-
config.size = 50
|
14
|
-
end
|
15
|
-
|
16
|
-
expect(Paginate.configuration.param_name).to eql(:p)
|
17
|
-
expect(Paginate.configuration.size).to eql(50)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns configuration as hash" do
|
21
|
-
Paginate.configure do |config|
|
22
|
-
config.param_name = :p
|
23
|
-
config.size = 25
|
24
|
-
config.renderer = Paginate::Renderer::List
|
25
|
-
end
|
26
|
-
|
27
|
-
options = {
|
28
|
-
param_name: :p,
|
29
|
-
size: 25,
|
30
|
-
renderer: Paginate::Renderer::List
|
31
|
-
}
|
32
|
-
|
33
|
-
expect(Paginate.configuration.to_hash).to eql(options)
|
34
|
-
end
|
35
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Paginate::Renderer::Base do
|
4
|
-
before do
|
5
|
-
Paginate.configure do |config|
|
6
|
-
config.param_name = :page
|
7
|
-
config.size = 10
|
8
|
-
end
|
9
|
-
|
10
|
-
I18n.locale = :en
|
11
|
-
|
12
|
-
@renderer = Paginate::Renderer::Base.new(nil, {
|
13
|
-
collection: Array.new(11),
|
14
|
-
page: 1,
|
15
|
-
fullpath: "/some/path"
|
16
|
-
})
|
17
|
-
end
|
18
|
-
|
19
|
-
it "parses simple url" do
|
20
|
-
@renderer.options[:url] = "/some/path"
|
21
|
-
expect(@renderer.url_for(1)).to eql("/some/path?page=1")
|
22
|
-
end
|
23
|
-
|
24
|
-
it "parses url with page param" do
|
25
|
-
@renderer.options[:url] = "/some/path?page=3"
|
26
|
-
expect(@renderer.url_for(1)).to eql("/some/path?page=1")
|
27
|
-
end
|
28
|
-
|
29
|
-
it "parses url with page as first param" do
|
30
|
-
@renderer.options[:url] = "/some/path?page=3&a=1&b=2&c=3"
|
31
|
-
expect(@renderer.url_for(1)).to eql("/some/path?a=1&b=2&c=3&page=1")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "parses url with page as last param" do
|
35
|
-
@renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=3"
|
36
|
-
expect(@renderer.url_for(1)).to eql("/some/path?a=1&b=2&c=3&page=1")
|
37
|
-
end
|
38
|
-
|
39
|
-
it "parses url with page param in the middle" do
|
40
|
-
@renderer.options[:url] = "/some/path?a=1&b=2&page=3&c=3"
|
41
|
-
expect(@renderer.url_for(1)).to eql("/some/path?a=1&b=2&c=3&page=1")
|
42
|
-
end
|
43
|
-
|
44
|
-
it "parses url with page as arbitrary string" do
|
45
|
-
@renderer.options[:url] = "/some/path?a=1&b=2&c=3&page=abc"
|
46
|
-
expect(@renderer.url_for(1)).to eql("/some/path?a=1&b=2&c=3&page=1")
|
47
|
-
end
|
48
|
-
|
49
|
-
it "escapes url from blocks" do
|
50
|
-
@renderer.options[:url] = proc {|page| "/some/path/#{page}?a=1&b=2"}
|
51
|
-
expect(@renderer.url_for(1)).to eql("/some/path/1?a=1&b=2")
|
52
|
-
end
|
53
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe Paginate::Renderer::List do
|
5
|
-
before do
|
6
|
-
Paginate.configure do |config|
|
7
|
-
config.param_name = :page
|
8
|
-
config.size = 10
|
9
|
-
end
|
10
|
-
|
11
|
-
I18n.locale = :en
|
12
|
-
|
13
|
-
@renderer = Paginate::Renderer::List.new(nil, {
|
14
|
-
collection: Array.new(11),
|
15
|
-
page: 1,
|
16
|
-
fullpath: "/some/path"
|
17
|
-
})
|
18
|
-
end
|
19
|
-
|
20
|
-
it { expect(@renderer.render).to be_html_safe }
|
21
|
-
it { expect(@renderer.previous_label).to eql(I18n.t("paginate.previous")) }
|
22
|
-
it { expect(@renderer.next_label).to eql(I18n.t("paginate.next")) }
|
23
|
-
it { expect(@renderer.page_label).to eql(I18n.t("paginate.page", page: 1)) }
|
24
|
-
|
25
|
-
it "displays current page" do
|
26
|
-
allow(@renderer.processor).to receive_messages page: 1234
|
27
|
-
|
28
|
-
html = Nokogiri::HTML(@renderer.render)
|
29
|
-
span = html.css("li.page > span").first
|
30
|
-
|
31
|
-
expect(span).to be
|
32
|
-
expect(span.text).to eql("Page 1234")
|
33
|
-
end
|
34
|
-
|
35
|
-
it "translates strings" do
|
36
|
-
I18n.locale = "pt-BR"
|
37
|
-
allow(@renderer.processor).to receive_messages page: 10
|
38
|
-
|
39
|
-
html = Nokogiri::HTML(@renderer.render)
|
40
|
-
|
41
|
-
expect(html.css("li.page > span").text).to eql("Página 10")
|
42
|
-
expect(html.css("li.next-page > a").text).to eql("Próxima página")
|
43
|
-
expect(html.css("li.previous-page > a").text).to eql("Página anterior")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "displays previous page link" do
|
47
|
-
allow(@renderer.processor).to receive_messages page: 2
|
48
|
-
|
49
|
-
html = Nokogiri::HTML(@renderer.render)
|
50
|
-
link = html.css("li.previous-page > a").first
|
51
|
-
|
52
|
-
expect(link).to be
|
53
|
-
expect(link["href"]).to eql("/some/path?page=1")
|
54
|
-
expect(link.text).to eql("Previous page")
|
55
|
-
end
|
56
|
-
|
57
|
-
it "displays next page link" do
|
58
|
-
allow(@renderer.processor).to receive_messages page: 1
|
59
|
-
|
60
|
-
html = Nokogiri::HTML(@renderer.render)
|
61
|
-
link = html.css("li.next-page > a").first
|
62
|
-
|
63
|
-
expect(link).to be
|
64
|
-
expect(link["href"]).to eql("/some/path?page=2")
|
65
|
-
expect(link.text).to eql("Next page")
|
66
|
-
end
|
67
|
-
|
68
|
-
it "displays pagination list" do
|
69
|
-
html = Nokogiri::HTML(@renderer.render)
|
70
|
-
|
71
|
-
expect(html.css("ul.paginate").count).to eql(1)
|
72
|
-
expect(html.css("ul.paginate > li").count).to eql(3)
|
73
|
-
end
|
74
|
-
|
75
|
-
context "when have no items" do
|
76
|
-
it "adds .disabled class to the list" do
|
77
|
-
allow(@renderer.processor).to receive_messages next_page?: false, previous_page?: false
|
78
|
-
|
79
|
-
html = Nokogiri::HTML(@renderer.render)
|
80
|
-
expect(html.css("ul.paginate.disabled").first).to be
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when have no next page" do
|
85
|
-
it "disables the element" do
|
86
|
-
allow(@renderer.processor).to receive :next_page?
|
87
|
-
|
88
|
-
html = Nokogiri::HTML(@renderer.render)
|
89
|
-
link = html.css("li.next-page > a").first
|
90
|
-
span = html.css("li.next-page.disabled > span").first
|
91
|
-
|
92
|
-
expect(link).not_to be
|
93
|
-
expect(span).to be
|
94
|
-
expect(span.text).to eql("Next page")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context "when no previous page" do
|
99
|
-
it "disables the element" do
|
100
|
-
allow(@renderer.processor).to receive :previous_page?
|
101
|
-
|
102
|
-
html = Nokogiri::HTML(@renderer.render)
|
103
|
-
link = html.css("li.previous-page > a").first
|
104
|
-
span = html.css("li.previous-page.disabled > span").first
|
105
|
-
|
106
|
-
expect(link).not_to be
|
107
|
-
expect(span).to be
|
108
|
-
expect(span.text).to eql("Previous page")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Paginate::Renderer::More do
|
4
|
-
before do
|
5
|
-
Paginate.configure do |config|
|
6
|
-
config.param_name = :page
|
7
|
-
config.size = 10
|
8
|
-
end
|
9
|
-
|
10
|
-
I18n.locale = :en
|
11
|
-
|
12
|
-
@renderer = Paginate::Renderer::More.new(nil, {
|
13
|
-
collection: Array.new(11),
|
14
|
-
page: 1,
|
15
|
-
fullpath: "/some/path"
|
16
|
-
})
|
17
|
-
end
|
18
|
-
|
19
|
-
it { expect(@renderer.render).to be_html_safe }
|
20
|
-
it { expect(@renderer.more_label).to eql(I18n.t("paginate.more")) }
|
21
|
-
|
22
|
-
context "when have no next page" do
|
23
|
-
it "returns nil" do
|
24
|
-
allow(@renderer.processor).to receive :next_page?
|
25
|
-
expect(@renderer.render).to be_nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when have next page" do
|
30
|
-
it "returns html" do
|
31
|
-
html = Nokogiri::HTML(@renderer.render)
|
32
|
-
selector = "p.paginate > a.more"
|
33
|
-
|
34
|
-
expect(html.css(selector).text).to eql(@renderer.more_label)
|
35
|
-
expect(html.css(selector).first[:href]).to eql(@renderer.next_url)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/spec/support/matchers.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<p class="number"><%= number %></p>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= render items, paginate: true, partial: "number" %>
|