folio-pagination 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.travis.yml +3 -0
- data/Gemfile +16 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +235 -0
- data/Rakefile +11 -0
- data/folio-pagination.gemspec +27 -0
- data/lib/folio/core_ext/enumerable.rb +51 -0
- data/lib/folio/invalid_page.rb +5 -0
- data/lib/folio/ordinal/page.rb +107 -0
- data/lib/folio/ordinal.rb +33 -0
- data/lib/folio/page.rb +86 -0
- data/lib/folio/per_page.rb +15 -0
- data/lib/folio/rails.rb +35 -0
- data/lib/folio/version.rb +3 -0
- data/lib/folio/will_paginate/active_record.rb +132 -0
- data/lib/folio/will_paginate/collection.rb +19 -0
- data/lib/folio/will_paginate/view_helpers/action_view.rb +10 -0
- data/lib/folio/will_paginate/view_helpers/link_renderer.rb +54 -0
- data/lib/folio/will_paginate/view_helpers/link_renderer_base.rb +44 -0
- data/lib/folio/will_paginate/view_helpers.rb +57 -0
- data/lib/folio-pagination.rb +3 -0
- data/lib/folio.rb +84 -0
- data/test/folio/core_ext/enumerable_test.rb +55 -0
- data/test/folio/ordinal/page_test.rb +173 -0
- data/test/folio/ordinal_test.rb +57 -0
- data/test/folio/page_test.rb +198 -0
- data/test/folio/per_page_test.rb +49 -0
- data/test/folio/rails_test.rb +15 -0
- data/test/folio/version_test.rb +8 -0
- data/test/folio/will_paginate/active_record_test.rb +118 -0
- data/test/folio/will_paginate/collection_test.rb +43 -0
- data/test/folio/will_paginate/view_helpers/link_renderer_base_test.rb +58 -0
- data/test/folio/will_paginate/view_helpers/link_renderer_test.rb +58 -0
- data/test/folio/will_paginate/view_helpers_test.rb +49 -0
- data/test/folio_test.rb +192 -0
- data/test/setup/active_record.rb +13 -0
- metadata +133 -0
data/test/folio_test.rb
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'folio'
|
3
|
+
|
4
|
+
describe Folio do
|
5
|
+
describe "class per_page" do
|
6
|
+
it "should have a per_page attribute" do
|
7
|
+
Folio.must_respond_to :per_page
|
8
|
+
Folio.must_respond_to :per_page=
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow setting by per_page=" do
|
12
|
+
was = Folio.per_page
|
13
|
+
Folio.per_page = 100
|
14
|
+
Folio.per_page.must_equal 100
|
15
|
+
Folio.per_page = was
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should allow setting by argument to per_page" do
|
19
|
+
was = Folio.per_page
|
20
|
+
Folio.per_page(100)
|
21
|
+
Folio.per_page.must_equal 100
|
22
|
+
Folio.per_page = was
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should default to 30" do
|
26
|
+
Folio.per_page.must_equal 30
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
page_klass = Class.new do
|
32
|
+
include Folio::Page
|
33
|
+
end
|
34
|
+
|
35
|
+
@klass = Class.new do
|
36
|
+
define_method :build_page do
|
37
|
+
page = page_klass.new
|
38
|
+
page.ordinal_pages = false
|
39
|
+
page.first_page = :first
|
40
|
+
page.last_page = :last
|
41
|
+
page
|
42
|
+
end
|
43
|
+
|
44
|
+
def fill_page(page)
|
45
|
+
page.next_page = :next
|
46
|
+
page.previous_page = :previous
|
47
|
+
page
|
48
|
+
end
|
49
|
+
|
50
|
+
include Folio
|
51
|
+
end
|
52
|
+
|
53
|
+
@folio = @klass.new
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "paginate" do
|
57
|
+
it "should get the page from the folio's build_page method" do
|
58
|
+
page = @folio.paginate
|
59
|
+
page.ordinal_pages.must_equal false
|
60
|
+
page.first_page.must_equal :first
|
61
|
+
page.last_page.must_equal :last
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should pass the page through the folio's fill_page method" do
|
65
|
+
page = @folio.paginate
|
66
|
+
page.next_page.must_equal :next
|
67
|
+
page.previous_page.must_equal :previous
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should populate current_page and per_page before passing it to fill_page" do
|
71
|
+
@klass.send(:define_method, :fill_page) do |page|
|
72
|
+
page.current_page.wont_be_nil
|
73
|
+
page.per_page.wont_be_nil
|
74
|
+
end
|
75
|
+
@folio.paginate
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "page parameter" do
|
79
|
+
it "should populate onto the page" do
|
80
|
+
page = @folio.paginate(page: :current)
|
81
|
+
page.current_page.must_equal :current
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should default to the page's first_page" do
|
85
|
+
page = @folio.paginate
|
86
|
+
page.current_page.must_equal page.first_page
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should set to the page's first_page if explicitly nil" do
|
90
|
+
page = @folio.paginate(page: nil)
|
91
|
+
page.current_page.must_equal page.first_page
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not set to the page's first_page if explicitly false" do
|
95
|
+
page = @folio.paginate(page: false)
|
96
|
+
page.current_page.must_equal false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "per_page parameter" do
|
101
|
+
it "should populate onto the page" do
|
102
|
+
page = @folio.paginate(per_page: 100)
|
103
|
+
page.per_page.must_equal 100
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should default to the folio's per_page" do
|
107
|
+
@folio.per_page = 100
|
108
|
+
page = @folio.paginate
|
109
|
+
page.per_page.must_equal 100
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "total_entries parameter" do
|
114
|
+
it "should populate onto the page" do
|
115
|
+
page = @folio.paginate(total_entries: 100)
|
116
|
+
page.total_entries.must_equal 100
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should default to the nil if the folio does not implement count" do
|
120
|
+
page = @folio.paginate
|
121
|
+
page.total_entries.must_be_nil
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should default to the result of count if the folio implements count" do
|
125
|
+
@klass.send(:define_method, :count) { 100 }
|
126
|
+
page = @folio.paginate
|
127
|
+
page.total_entries.must_equal 100
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should not-execute the count if total_entries provided" do
|
131
|
+
called = false
|
132
|
+
@klass.send(:define_method, :count) { called = true }
|
133
|
+
@folio.paginate(total_entries: 100)
|
134
|
+
called.must_equal false
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should not-execute the count if total_entries provided as nil" do
|
138
|
+
called = false
|
139
|
+
@klass.send(:define_method, :count) { called = true }
|
140
|
+
page = @folio.paginate(total_entries: nil)
|
141
|
+
called.must_equal false
|
142
|
+
page.total_entries.must_be_nil
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "per_page class attribute" do
|
148
|
+
it "should exist" do
|
149
|
+
@klass.must_respond_to :per_page
|
150
|
+
@klass.must_respond_to :per_page=
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should be settable from per_page=" do
|
154
|
+
@klass.per_page = 100
|
155
|
+
@klass.per_page.must_equal 100
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should be settable from per_page with argument" do
|
159
|
+
@klass.per_page(100)
|
160
|
+
@klass.per_page.must_equal 100
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should default to Folio.per_page" do
|
164
|
+
was = Folio.per_page
|
165
|
+
Folio.per_page = 50
|
166
|
+
@klass.per_page.must_equal 50
|
167
|
+
Folio.per_page = was
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "per_page instance attribute" do
|
172
|
+
it "should exist" do
|
173
|
+
@folio.must_respond_to :per_page
|
174
|
+
@folio.must_respond_to :per_page=
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should be settable from per_page=" do
|
178
|
+
@folio.per_page = 100
|
179
|
+
@folio.per_page.must_equal 100
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should be settable from per_page with argument" do
|
183
|
+
@folio.per_page(100)
|
184
|
+
@folio.per_page.must_equal 100
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should default to class' per_page" do
|
188
|
+
@klass.per_page = 50
|
189
|
+
@folio.per_page.must_equal 50
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
4
|
+
|
5
|
+
module TestSetup
|
6
|
+
module ActiveRecord
|
7
|
+
def self.migrate
|
8
|
+
::ActiveRecord::Migration.suppress_messages do
|
9
|
+
yield ::ActiveRecord::Migration
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: folio-pagination
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jacob Fugal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A pagination library.
|
47
|
+
email:
|
48
|
+
- jacob@instructure.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .travis.yml
|
55
|
+
- Gemfile
|
56
|
+
- Guardfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- folio-pagination.gemspec
|
61
|
+
- lib/folio-pagination.rb
|
62
|
+
- lib/folio.rb
|
63
|
+
- lib/folio/core_ext/enumerable.rb
|
64
|
+
- lib/folio/invalid_page.rb
|
65
|
+
- lib/folio/ordinal.rb
|
66
|
+
- lib/folio/ordinal/page.rb
|
67
|
+
- lib/folio/page.rb
|
68
|
+
- lib/folio/per_page.rb
|
69
|
+
- lib/folio/rails.rb
|
70
|
+
- lib/folio/version.rb
|
71
|
+
- lib/folio/will_paginate/active_record.rb
|
72
|
+
- lib/folio/will_paginate/collection.rb
|
73
|
+
- lib/folio/will_paginate/view_helpers.rb
|
74
|
+
- lib/folio/will_paginate/view_helpers/action_view.rb
|
75
|
+
- lib/folio/will_paginate/view_helpers/link_renderer.rb
|
76
|
+
- lib/folio/will_paginate/view_helpers/link_renderer_base.rb
|
77
|
+
- test/folio/core_ext/enumerable_test.rb
|
78
|
+
- test/folio/ordinal/page_test.rb
|
79
|
+
- test/folio/ordinal_test.rb
|
80
|
+
- test/folio/page_test.rb
|
81
|
+
- test/folio/per_page_test.rb
|
82
|
+
- test/folio/rails_test.rb
|
83
|
+
- test/folio/version_test.rb
|
84
|
+
- test/folio/will_paginate/active_record_test.rb
|
85
|
+
- test/folio/will_paginate/collection_test.rb
|
86
|
+
- test/folio/will_paginate/view_helpers/link_renderer_base_test.rb
|
87
|
+
- test/folio/will_paginate/view_helpers/link_renderer_test.rb
|
88
|
+
- test/folio/will_paginate/view_helpers_test.rb
|
89
|
+
- test/folio_test.rb
|
90
|
+
- test/setup/active_record.rb
|
91
|
+
homepage: https://github.com/instructure/folio
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.8.23
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Folio is a library for pagination. It's meant to be nearly compatible with
|
116
|
+
WillPaginate, but with broader -- yet more well-defined -- semantics to allow for
|
117
|
+
sources whose page identifiers are non-ordinal.
|
118
|
+
test_files:
|
119
|
+
- test/folio/core_ext/enumerable_test.rb
|
120
|
+
- test/folio/ordinal/page_test.rb
|
121
|
+
- test/folio/ordinal_test.rb
|
122
|
+
- test/folio/page_test.rb
|
123
|
+
- test/folio/per_page_test.rb
|
124
|
+
- test/folio/rails_test.rb
|
125
|
+
- test/folio/version_test.rb
|
126
|
+
- test/folio/will_paginate/active_record_test.rb
|
127
|
+
- test/folio/will_paginate/collection_test.rb
|
128
|
+
- test/folio/will_paginate/view_helpers/link_renderer_base_test.rb
|
129
|
+
- test/folio/will_paginate/view_helpers/link_renderer_test.rb
|
130
|
+
- test/folio/will_paginate/view_helpers_test.rb
|
131
|
+
- test/folio_test.rb
|
132
|
+
- test/setup/active_record.rb
|
133
|
+
has_rdoc:
|