paginate-responder 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ gemspec
6
6
  group :development do
7
7
  gem 'minitest'
8
8
  gem 'rake'
9
- gem 'rack-link_headers', :path => '../rack-link-headers'
9
+ gem 'rack-link_headers'
10
10
  end
11
11
 
12
12
  group :test do
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Paginate::Responder
1
+ # Paginate::Responder [![Build Status](https://travis-ci.org/jgraichen/paginate-responder.png?branch=master)](https://travis-ci.org/jgraichen/paginate-responder)
2
2
 
3
3
  A Rails pagination responder with link header support.
4
4
 
@@ -1,7 +1,7 @@
1
1
  module PaginateResponder
2
2
  module VERSION
3
3
  MAJOR = 1
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
  STAGE = nil
7
7
 
@@ -5,10 +5,10 @@ module Responders
5
5
  if get? && resource.respond_to?(:paginate)
6
6
  @resource = resource.paginate :page => self.page, :per_page => self.per_page
7
7
 
8
- controller.response.link("first", controller.url_for(request.params.merge(:page => 1)))
9
- controller.response.link("prev", controller.url_for(request.params.merge(:page => page - 1))) if page > 1
10
- controller.response.link("next", controller.url_for(request.params.merge(:page => page + 1))) if total_pages && (page+1) < total_pages
11
- controller.response.link("last", controller.url_for(request.params.merge(:page => total_pages))) if total_pages
8
+ controller.response.link(controller.url_for(request.params.merge(:page => 1)), :rel => "first")
9
+ controller.response.link(controller.url_for(request.params.merge(:page => page - 1)), :rel => "prev") if page > 1
10
+ controller.response.link(controller.url_for(request.params.merge(:page => page + 1)), :rel => "next") if total_pages && page < total_pages
11
+ controller.response.link(controller.url_for(request.params.merge(:page => total_pages)), :rel => "last") if total_pages
12
12
  controller.response.headers["X-Total-Pages"] = total_pages if total_pages
13
13
  end
14
14
  super
@@ -17,5 +17,5 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency 'rack-link_headers'
20
+ gem.add_dependency 'rack-link_headers', '>= 2.2'
21
21
  end
@@ -38,31 +38,49 @@ class PaginateResponderTest < ActionController::TestCase
38
38
 
39
39
  assert_equal 3, response.links.size
40
40
 
41
- assert_equal "first", response.links[0][:rel]
41
+ assert_equal "first", response.links[0][:params][:rel]
42
42
  assert_equal "http://test.host/index.json?page=1", response.links[0][:url]
43
43
 
44
- assert_equal "next", response.links[1][:rel]
44
+ assert_equal "next", response.links[1][:params][:rel]
45
45
  assert_equal "http://test.host/index.json?page=2", response.links[1][:url]
46
46
 
47
- assert_equal "last", response.links[2][:rel]
47
+ assert_equal "last", response.links[2][:params][:rel]
48
48
  assert_equal "http://test.host/index.json?page=14", response.links[2][:url]
49
49
  end
50
50
 
51
+ def test_headers_page_2
52
+ get :index, :format => :json, :page => 2
53
+
54
+ assert_equal 4, response.links.size
55
+
56
+ assert_equal "first", response.links[0][:params][:rel]
57
+ assert_equal "http://test.host/index.json?page=1", response.links[0][:url]
58
+
59
+ assert_equal "prev", response.links[1][:params][:rel]
60
+ assert_equal "http://test.host/index.json?page=1", response.links[1][:url]
61
+
62
+ assert_equal "next", response.links[2][:params][:rel]
63
+ assert_equal "http://test.host/index.json?page=3", response.links[2][:url]
64
+
65
+ assert_equal "last", response.links[3][:params][:rel]
66
+ assert_equal "http://test.host/index.json?page=14", response.links[3][:url]
67
+ end
68
+
51
69
  def test_headers_page_5
52
70
  get :index, :format => :json, :page => 5
53
71
 
54
72
  assert_equal 4, response.links.size
55
73
 
56
- assert_equal "first", response.links[0][:rel]
74
+ assert_equal "first", response.links[0][:params][:rel]
57
75
  assert_equal "http://test.host/index.json?page=1", response.links[0][:url]
58
76
 
59
- assert_equal "prev", response.links[1][:rel]
77
+ assert_equal "prev", response.links[1][:params][:rel]
60
78
  assert_equal "http://test.host/index.json?page=4", response.links[1][:url]
61
79
 
62
- assert_equal "next", response.links[2][:rel]
80
+ assert_equal "next", response.links[2][:params][:rel]
63
81
  assert_equal "http://test.host/index.json?page=6", response.links[2][:url]
64
82
 
65
- assert_equal "last", response.links[3][:rel]
83
+ assert_equal "last", response.links[3][:params][:rel]
66
84
  assert_equal "http://test.host/index.json?page=14", response.links[3][:url]
67
85
  end
68
86
 
@@ -71,28 +89,46 @@ class PaginateResponderTest < ActionController::TestCase
71
89
 
72
90
  assert_equal 3, response.links.size
73
91
 
74
- assert_equal "first", response.links[0][:rel]
92
+ assert_equal "first", response.links[0][:params][:rel]
75
93
  assert_equal "http://test.host/index.json?page=1", response.links[0][:url]
76
94
 
77
- assert_equal "prev", response.links[1][:rel]
95
+ assert_equal "prev", response.links[1][:params][:rel]
78
96
  assert_equal "http://test.host/index.json?page=13", response.links[1][:url]
79
97
 
80
- assert_equal "last", response.links[2][:rel]
98
+ assert_equal "last", response.links[2][:params][:rel]
81
99
  assert_equal "http://test.host/index.json?page=14", response.links[2][:url]
82
100
  end
83
101
 
102
+ def test_headers_page_before_last_page
103
+ get :index, :format => :json, :page => 13
104
+
105
+ assert_equal 4, response.links.size
106
+
107
+ assert_equal "first", response.links[0][:params][:rel]
108
+ assert_equal "http://test.host/index.json?page=1", response.links[0][:url]
109
+
110
+ assert_equal "prev", response.links[1][:params][:rel]
111
+ assert_equal "http://test.host/index.json?page=12", response.links[1][:url]
112
+
113
+ assert_equal "next", response.links[2][:params][:rel]
114
+ assert_equal "http://test.host/index.json?page=14", response.links[2][:url]
115
+
116
+ assert_equal "last", response.links[3][:params][:rel]
117
+ assert_equal "http://test.host/index.json?page=14", response.links[3][:url]
118
+ end
119
+
84
120
  def test_headers_per_page
85
121
  get :index, :format => :json, :page => 1, :per_page => 10
86
122
 
87
123
  assert_equal 3, response.links.size
88
124
 
89
- assert_equal "first", response.links[0][:rel]
125
+ assert_equal "first", response.links[0][:params][:rel]
90
126
  assert_equal "http://test.host/index.json?page=1&per_page=10", response.links[0][:url]
91
127
 
92
- assert_equal "next", response.links[1][:rel]
128
+ assert_equal "next", response.links[1][:params][:rel]
93
129
  assert_equal "http://test.host/index.json?page=2&per_page=10", response.links[1][:url]
94
130
 
95
- assert_equal "last", response.links[2][:rel]
131
+ assert_equal "last", response.links[2][:params][:rel]
96
132
  assert_equal "http://test.host/index.json?page=68&per_page=10", response.links[2][:url]
97
133
  end
98
134
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paginate-responder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack-link_headers
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: '2.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: '2.2'
30
30
  description: A Rails pagination responder with link header support.
31
31
  email:
32
32
  - jg@altimos.de
@@ -60,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  version: '0'
61
61
  segments:
62
62
  - 0
63
- hash: -1984734961715854545
63
+ hash: -2632353665928065861
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  version: '0'
70
70
  segments:
71
71
  - 0
72
- hash: -1984734961715854545
72
+ hash: -2632353665928065861
73
73
  requirements: []
74
74
  rubyforge_project:
75
75
  rubygems_version: 1.8.24