pagers 3.0.3 → 3.1.0

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/pagers/install_generator.rb +13 -0
  3. data/lib/generators/pagers/templates/pagers.rb +2 -0
  4. data/lib/pagers/action_view/base.rb +3 -3
  5. data/lib/pagers/active_record/base.rb +2 -2
  6. data/lib/pagers/railtie.rb +0 -6
  7. data/lib/pagers/version.rb +1 -1
  8. data/lib/pagers.rb +18 -0
  9. data/test/dummy/app/controllers/pages_controller.rb +1 -1
  10. data/test/dummy/app/models/record.rb +2 -0
  11. data/test/dummy/config/routes.rb +0 -3
  12. data/test/dummy/db/migrate/{20130820024335_create_models.rb → 20130820024335_create_records.rb} +1 -1
  13. data/test/dummy/db/schema.rb +1 -1
  14. data/test/dummy/db/test.sqlite3 +0 -0
  15. data/test/dummy/log/development.log +24 -0
  16. data/test/dummy/log/test.log +45976 -0
  17. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  18. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  19. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  20. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  21. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  22. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  23. data/test/empty_test.rb +9 -9
  24. data/test/first_test.rb +10 -10
  25. data/test/generator_test.rb +18 -0
  26. data/test/last_test.rb +10 -10
  27. data/test/middle_test.rb +10 -10
  28. data/test/padding_test.rb +5 -37
  29. data/test/route_test.rb +37 -0
  30. metadata +24 -9
  31. data/README.rdoc +0 -40
  32. data/test/dummy/app/models/model.rb +0 -2
  33. data/test/dummy/db/development.sqlite3 +0 -0
data/test/empty_test.rb CHANGED
@@ -1,39 +1,39 @@
1
1
  require 'test_helper'
2
2
 
3
- class RelationEmptyTest < ActiveSupport::TestCase
3
+ class EmptyTest < ActiveSupport::TestCase
4
4
 
5
- test "should have 1 page" do
5
+ test 'should have 1 page' do
6
6
  assert_equal 1, relation.total_pages
7
7
  end
8
8
 
9
- test "current page should be 1" do
9
+ test 'current page should be 1' do
10
10
  assert_equal 1, relation.current_page
11
11
  end
12
12
 
13
- test "first page should be 1" do
13
+ test 'first page should be 1' do
14
14
  assert_equal 1, relation.first_page
15
15
  end
16
16
 
17
- test "should have no previous page" do
17
+ test 'should have no previous page' do
18
18
  assert_nil relation.previous_page
19
19
  end
20
20
 
21
- test "should have no next page" do
21
+ test 'should have no next page' do
22
22
  assert_nil relation.next_page
23
23
  end
24
24
 
25
- test "last page should be 1" do
25
+ test 'last page should be 1' do
26
26
  assert_equal 1, relation.last_page
27
27
  end
28
28
 
29
- test "should not be out of bounds" do
29
+ test 'should not be out of bounds' do
30
30
  assert !relation.out_of_bounds?
31
31
  end
32
32
 
33
33
  protected
34
34
 
35
35
  def relation
36
- @relation ||= Model.page(1, length: 2)
36
+ @relation ||= Record.page(1, length: 2)
37
37
  end
38
38
 
39
39
  end
data/test/first_test.rb CHANGED
@@ -1,43 +1,43 @@
1
1
  require 'test_helper'
2
2
 
3
- class RelationFirstTest < ActiveSupport::TestCase
3
+ class FirstTest < ActiveSupport::TestCase
4
4
 
5
5
  setup do
6
- 10.times.each { |index| Model.create name: index }
6
+ 10.times.each { |index| Record.create }
7
7
  end
8
8
 
9
- test "should have 5 pages" do
9
+ test 'should have 5 pages' do
10
10
  assert_equal 5, relation.total_pages
11
11
  end
12
12
 
13
- test "current page should be 1" do
13
+ test 'current page should be 1' do
14
14
  assert_equal 1, relation.current_page
15
15
  end
16
16
 
17
- test "first page should be 1" do
17
+ test 'first page should be 1' do
18
18
  assert_equal 1, relation.first_page
19
19
  end
20
20
 
21
- test "should have no previous page" do
21
+ test 'should have no previous page' do
22
22
  assert_nil relation.previous_page
23
23
  end
24
24
 
25
- test "next page should be 2" do
25
+ test 'next page should be 2' do
26
26
  assert_equal 2, relation.next_page
27
27
  end
28
28
 
29
- test "last page shuold be 5" do
29
+ test 'last page shuold be 5' do
30
30
  assert_equal 5, relation.last_page
31
31
  end
32
32
 
33
- test "should not be out of bounds" do
33
+ test 'should not be out of bounds' do
34
34
  assert !relation.out_of_bounds?
35
35
  end
36
36
 
37
37
  protected
38
38
 
39
39
  def relation
40
- @relation ||= Model.page(1, length: 2)
40
+ @relation ||= Record.page(1, length: 2)
41
41
  end
42
42
 
43
43
  end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+ require 'rails/generators'
3
+ require 'generators/pagers/install_generator'
4
+
5
+ class GeneratorsTest < Rails::Generators::TestCase
6
+ tests Pagers::InstallGenerator
7
+ destination File.expand_path('../tmp', File.dirname(__FILE__))
8
+
9
+ teardown do
10
+ FileUtils.rm_rf self.destination_root
11
+ end
12
+
13
+ test 'generate initializer' do
14
+ run_generator
15
+ assert_file 'config/initializers/pagers.rb'
16
+ end
17
+
18
+ end
data/test/last_test.rb CHANGED
@@ -1,43 +1,43 @@
1
1
  require 'test_helper'
2
2
 
3
- class RelationLastTest < ActiveSupport::TestCase
3
+ class LastTest < ActiveSupport::TestCase
4
4
 
5
5
  setup do
6
- 10.times.each { |index| Model.create name: index }
6
+ 10.times.each { |index| Record.create }
7
7
  end
8
8
 
9
- test "should have 5 pages" do
9
+ test 'should have 5 pages' do
10
10
  assert_equal 5, relation.total_pages
11
11
  end
12
12
 
13
- test "current page should be 5" do
13
+ test 'current page should be 5' do
14
14
  assert_equal 5, relation.current_page
15
15
  end
16
16
 
17
- test "first page should be 1" do
17
+ test 'first page should be 1' do
18
18
  assert_equal 1, relation.first_page
19
19
  end
20
20
 
21
- test "should have previous page 4" do
21
+ test 'should have previous page 4' do
22
22
  assert_equal 4, relation.previous_page
23
23
  end
24
24
 
25
- test "should not have next page" do
25
+ test 'should not have next page' do
26
26
  assert_nil relation.next_page
27
27
  end
28
28
 
29
- test "last page shuold be 5" do
29
+ test 'last page shuold be 5' do
30
30
  assert_equal 5, relation.last_page
31
31
  end
32
32
 
33
- test "should not be out of bounds" do
33
+ test 'should not be out of bounds' do
34
34
  assert !relation.out_of_bounds?
35
35
  end
36
36
 
37
37
  protected
38
38
 
39
39
  def relation
40
- @relation ||= Model.page(5, length: 2)
40
+ @relation ||= Record.page(5, length: 2)
41
41
  end
42
42
 
43
43
  end
data/test/middle_test.rb CHANGED
@@ -1,43 +1,43 @@
1
1
  require 'test_helper'
2
2
 
3
- class RelationMiddleTest < ActiveSupport::TestCase
3
+ class MiddleTest < ActiveSupport::TestCase
4
4
 
5
5
  setup do
6
- 10.times.each { |index| Model.create name: index }
6
+ 10.times.each { |index| Record.create }
7
7
  end
8
8
 
9
- test "should have 5 pages" do
9
+ test 'should have 5 pages' do
10
10
  assert_equal 5, relation.total_pages
11
11
  end
12
12
 
13
- test "current page should be 3" do
13
+ test 'current page should be 3' do
14
14
  assert_equal 3, relation.current_page
15
15
  end
16
16
 
17
- test "first page should be 1" do
17
+ test 'first page should be 1' do
18
18
  assert_equal 1, relation.first_page
19
19
  end
20
20
 
21
- test "should have previous page 2" do
21
+ test 'should have previous page 2' do
22
22
  assert_equal 2, relation.previous_page
23
23
  end
24
24
 
25
- test "should have next page 4" do
25
+ test 'should have next page 4' do
26
26
  assert_equal 4, relation.next_page
27
27
  end
28
28
 
29
- test "last page shuold be 5" do
29
+ test 'last page shuold be 5' do
30
30
  assert_equal 5, relation.last_page
31
31
  end
32
32
 
33
- test "should not be out of bounds" do
33
+ test 'should not be out of bounds' do
34
34
  assert !relation.out_of_bounds?
35
35
  end
36
36
 
37
37
  protected
38
38
 
39
39
  def relation
40
- @relation ||= Model.page(3, length: 2)
40
+ @relation ||= Record.page(3, length: 2)
41
41
  end
42
42
 
43
43
  end
data/test/padding_test.rb CHANGED
@@ -2,52 +2,20 @@ require 'test_helper'
2
2
 
3
3
  class PaddingTest < ActiveSupport::TestCase
4
4
 
5
- test "negative padding should have 1 page" do
6
- 19.times.each { |index| Model.create name: index }
5
+ test 'padding not alter total pages' do
6
+ 19.times.each { |index| Record.create }
7
7
 
8
- relation = Model.page(1, length: 15, padding: 4)
8
+ relation = Record.page(1, length: 15, padding: 4)
9
9
  assert_equal 15, relation.size
10
10
  assert_equal 1, relation.total_pages
11
11
 
12
- relation = Model.page(2, length: 15, padding: 4)
12
+ relation = Record.page(2, length: 15, padding: 4)
13
13
  assert_equal 0, relation.size
14
14
  assert_equal 1, relation.total_pages
15
15
 
16
- relation = Model.page(3, length: 15, padding: 4)
16
+ relation = Record.page(3, length: 15, padding: 4)
17
17
  assert_equal 0, relation.size
18
18
  assert_equal 1, relation.total_pages
19
19
  end
20
20
 
21
- test "negative padding should have 2 pages" do
22
- 34.times.each { |index| Model.create name: index }
23
-
24
- relation = Model.page(1, length: 15, padding: 4)
25
- assert_equal 15, relation.size
26
- assert_equal 2, relation.total_pages
27
-
28
- relation = Model.page(2, length: 15, padding: 4)
29
- assert_equal 15, relation.size
30
- assert_equal 2, relation.total_pages
31
-
32
- relation = Model.page(3, length: 15, padding: 4)
33
- assert_equal 0, relation.size
34
- assert_equal 2, relation.total_pages
35
- end
36
-
37
- test "negative padding should have 3 pages" do
38
- 49.times.each { |index| Model.create name: index }
39
-
40
- relation = Model.page(1, length: 15, padding: 4)
41
- assert_equal 15, relation.size
42
- assert_equal 3, relation.total_pages
43
-
44
- relation = Model.page(2, length: 15, padding: 4)
45
- assert_equal 15, relation.size
46
- assert_equal 3, relation.total_pages
47
-
48
- relation = Model.page(3, length: 15, padding: 4)
49
- assert_equal 15, relation.size
50
- assert_equal 3, relation.total_pages
51
- end
52
-
53
21
  end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class RouteTest < ActionDispatch::IntegrationTest
4
+
5
+ test 'query page param' do
6
+ Rails.application.routes.draw do
7
+ get '/' => 'pages#index'
8
+ end
9
+
10
+ 10.times.each { Record.create }
11
+ get '/'
12
+ assert_select 'li.current a[href=/?page=1]', '1'
13
+ get '/?page=2'
14
+ assert_select 'li.current a[href=/?page=2]', '2'
15
+ get '/?dummy='
16
+ assert_select 'li.current a[href=/?dummy=&amp;page=1]', '1'
17
+ get '/?dummy=&page=2'
18
+ assert_select 'li.current a[href=/?dummy=&amp;page=2]', '2'
19
+ end
20
+
21
+ test 'route page param' do
22
+ Rails.application.routes.draw do
23
+ get '(:page)' => 'pages#index'
24
+ end
25
+
26
+ 10.times.each { Record.create }
27
+ get '/'
28
+ assert_select 'li.current a[href=/1]', '1'
29
+ get '/2'
30
+ assert_select 'li.current a[href=/2]', '2'
31
+ get '/?dummy='
32
+ assert_select 'li.current a[href=/1?dummy=]', '1'
33
+ get '/2?dummy='
34
+ assert_select 'li.current a[href=/2?dummy=]', '2'
35
+ end
36
+
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Museways
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-25 00:00:00.000000000 Z
11
+ date: 2014-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,11 +52,12 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - MIT-LICENSE
55
- - README.rdoc
56
55
  - Rakefile
57
56
  - app/views/pagers/_main.html.erb
58
57
  - config/locales/en.yml
59
58
  - config/locales/es.yml
59
+ - lib/generators/pagers/install_generator.rb
60
+ - lib/generators/pagers/templates/pagers.rb
60
61
  - lib/pagers.rb
61
62
  - lib/pagers/action_view/base.rb
62
63
  - lib/pagers/active_record/base.rb
@@ -71,7 +72,7 @@ files:
71
72
  - test/dummy/app/controllers/application_controller.rb
72
73
  - test/dummy/app/controllers/pages_controller.rb
73
74
  - test/dummy/app/helpers/application_helper.rb
74
- - test/dummy/app/models/model.rb
75
+ - test/dummy/app/models/record.rb
75
76
  - test/dummy/app/views/layouts/application.html.erb
76
77
  - test/dummy/app/views/pages/index.html.erb
77
78
  - test/dummy/bin/bundle
@@ -94,8 +95,7 @@ files:
94
95
  - test/dummy/config/initializers/wrap_parameters.rb
95
96
  - test/dummy/config/locales/en.yml
96
97
  - test/dummy/config/routes.rb
97
- - test/dummy/db/development.sqlite3
98
- - test/dummy/db/migrate/20130820024335_create_models.rb
98
+ - test/dummy/db/migrate/20130820024335_create_records.rb
99
99
  - test/dummy/db/schema.rb
100
100
  - test/dummy/db/test.sqlite3
101
101
  - test/dummy/log/development.log
@@ -110,11 +110,19 @@ files:
110
110
  - test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994
111
111
  - test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6
112
112
  - test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655
113
+ - test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
114
+ - test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
115
+ - test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
116
+ - test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
117
+ - test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
118
+ - test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
113
119
  - test/empty_test.rb
114
120
  - test/first_test.rb
121
+ - test/generator_test.rb
115
122
  - test/last_test.rb
116
123
  - test/middle_test.rb
117
124
  - test/padding_test.rb
125
+ - test/route_test.rb
118
126
  - test/test_helper.rb
119
127
  homepage: https://github.com/museways/pagers
120
128
  licenses:
@@ -146,7 +154,7 @@ test_files:
146
154
  - test/dummy/app/controllers/application_controller.rb
147
155
  - test/dummy/app/controllers/pages_controller.rb
148
156
  - test/dummy/app/helpers/application_helper.rb
149
- - test/dummy/app/models/model.rb
157
+ - test/dummy/app/models/record.rb
150
158
  - test/dummy/app/views/layouts/application.html.erb
151
159
  - test/dummy/app/views/pages/index.html.erb
152
160
  - test/dummy/bin/bundle
@@ -169,8 +177,7 @@ test_files:
169
177
  - test/dummy/config/locales/en.yml
170
178
  - test/dummy/config/routes.rb
171
179
  - test/dummy/config.ru
172
- - test/dummy/db/development.sqlite3
173
- - test/dummy/db/migrate/20130820024335_create_models.rb
180
+ - test/dummy/db/migrate/20130820024335_create_records.rb
174
181
  - test/dummy/db/schema.rb
175
182
  - test/dummy/db/test.sqlite3
176
183
  - test/dummy/log/development.log
@@ -187,9 +194,17 @@ test_files:
187
194
  - test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994
188
195
  - test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6
189
196
  - test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655
197
+ - test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705
198
+ - test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af
199
+ - test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953
200
+ - test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994
201
+ - test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6
202
+ - test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
190
203
  - test/empty_test.rb
191
204
  - test/first_test.rb
205
+ - test/generator_test.rb
192
206
  - test/last_test.rb
193
207
  - test/middle_test.rb
194
208
  - test/padding_test.rb
209
+ - test/route_test.rb
195
210
  - test/test_helper.rb
data/README.rdoc DELETED
@@ -1,40 +0,0 @@
1
- {<img src="https://badge.fury.io/rb/pagers.png" alt="Gem Version" />}[http://badge.fury.io/rb/pagers] {<img src="https://codeclimate.com/github/museways/pagers.png" />}[https://codeclimate.com/github/museways/pagers] {<img src="https://travis-ci.org/museways/pagers.png?branch=master" alt="Build Status" />}[https://travis-ci.org/museways/pagers]
2
-
3
- = Pagers
4
-
5
- Minimalistic pagers inspired in kaminari and will_paginate for rails.
6
-
7
- = Install
8
-
9
- Put this line in your Gemfile:
10
- gem 'pagers'
11
-
12
- Then bundle:
13
- $ bundle
14
-
15
- = Usage
16
-
17
- Call the page scope from your models:
18
- @collection = Model.page(1, length: 10, padding: 4)
19
-
20
- And in your views just:
21
- <%= paginate @collection %>
22
-
23
- You can customize the parameter and the pages if you like:
24
- <%= paginate @collection, parameter: :p, pages: 3 %>
25
-
26
- = Configuration
27
-
28
- All the defaults can be customized globally in your application.rb:
29
- config.pagers.parameter = :p
30
- config.pagers.pages = 3
31
- config.pagers.length = 5
32
- config.pagers.padding = 0
33
-
34
- = Credits
35
-
36
- This gem is maintained and funded by museways[http://museways.com].
37
-
38
- = License
39
-
40
- It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
@@ -1,2 +0,0 @@
1
- class Model < ActiveRecord::Base
2
- end
Binary file