api-versions 1.2.0 → 1.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76c06f9b24fbbbce7345e61b4cce9a66f955f32a
4
- data.tar.gz: d596f61158abb67ba28f5b7200a8f774416bb33d
3
+ metadata.gz: 8edd7dd575a06946e485d061aa3453b0d122e25a
4
+ data.tar.gz: cedef947d6ff68d8cbf2f8a33a0b3422a3ca3c1b
5
5
  SHA512:
6
- metadata.gz: 9243f84c3b74cae3311a3cfd01a6cd63f8d28cf5f2df870aa6c9afd915858cef2bc91d26f1fe79ef1d914cee6a2ddbdfa464a36d4e095f60faa83aecc65e0eac
7
- data.tar.gz: 293cb32aaaa8b3b2953c38235778307a88e452ff512fe845ecc05a9270db3e18a9deabd794520bb2bff48f6c47229347ee788f759058a306d4167032a664d3ad
6
+ metadata.gz: ad2e9a388fe6741320e6b626a1078a6eccdb28dcb97f249ae2ed5e734b843c9cbf3752300bc37e0275364fc4c6e42bb2bc4c314e24c3cd8bb7cbced4631284e8
7
+ data.tar.gz: f62e2d9c1d466d8207e0d1b5229e6c24e41b648df498f9bd560de84a8d9c57b199a8d31ea0a3ec3fb5ff9c807b979aa08e1a3999e68c233ccf1ff7d5ce93c5d1
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ pkg/*
5
5
  spec/dummy/log/*
6
6
  log/*
7
7
  tmp/*
8
+ coverage/*
@@ -8,11 +8,13 @@ notifications:
8
8
  email:
9
9
  recipients:
10
10
  - api-versions@erich.erichmenge.com
11
+ - me@davidcel.is
11
12
  env:
12
13
  - RAILS_VERSION=3-0-stable
13
14
  - RAILS_VERSION=3-1-stable
14
15
  - RAILS_VERSION=3-2-stable
15
16
  - RAILS_VERSION=4-0-stable
17
+ - RAILS_VERSION=4.0.0
16
18
  - RAILS_VERSION=master
17
19
 
18
20
  matrix:
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # api-versions
2
2
 
3
- [![Build Status](https://travis-ci.org/erichmenge/api-versions.png?branch=master)](https://travis-ci.org/erichmenge/api-versions)
3
+ [![Build Status](https://travis-ci.org/EDMC/api-versions.png?branch=master)](https://travis-ci.org/EDMC/api-versions)
4
4
  [![Gem Version](https://badge.fury.io/rb/api-versions.png)](http://badge.fury.io/rb/api-versions)
5
-
5
+ [![Coverage Status](https://coveralls.io/repos/erichmenge/api-versions/badge.png)](https://coveralls.io/r/erichmenge/api-versions)
6
+ [![Code Climate](https://codeclimate.com/github/erichmenge/api-versions.png)](https://codeclimate.com/github/erichmenge/api-versions)
6
7
 
7
8
  ### Requirements
8
9
  * Rails 4 or Rails 3
@@ -206,3 +207,39 @@ Then a `rake routes` would show your desires fulfilled:
206
207
  PUT /foo/:id(.:format) api/v2/foo#update
207
208
  DELETE /foo/:id(.:format) api/v2/foo#destroy
208
209
  ```
210
+
211
+ ## Testing
212
+ Because controller tests will not go through the routing constraints, you will get routing errors when testing API
213
+ controllers.
214
+
215
+ To avoid this problem you can use request/integration tests which will hit the routing constraints.
216
+
217
+ To do this in RSpec, you should only need to move your spec files from `spec/controllers.` to `spec/requests/`:
218
+
219
+ ```ruby
220
+ # spec/requests/api/v1/widgets_controller_spec.rb
221
+ require 'spec_helper'
222
+
223
+ describe Api::V1::WidgetsController do
224
+ describe "GET 'index'" do
225
+ it "should be successful" do
226
+ get '/api/widgets', {}, 'HTTP_ACCEPT' => 'application/vnd.myvendor+json; version=1'
227
+ response.should be_success
228
+ end
229
+ end
230
+ end
231
+ ```
232
+
233
+ For Test::Unit, inherit from ActionDispatch::IntegrationTest:
234
+
235
+ ```ruby
236
+ # test/integration/api/v1/widgets_controller_test.rb
237
+ require 'test_helper'
238
+
239
+ class Api::V1::WidgetsControllerTest < ActionDispatch::IntegrationTest
240
+ test "GET 'index'" do
241
+ get '/api/widgets', {}, 'HTTP_ACCEPT' => 'application/vnd.myvendor+json; version=1'
242
+ assert_response 200
243
+ end
244
+ end
245
+ ```
@@ -5,14 +5,12 @@ require "api-versions/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "api-versions"
7
7
  s.version = ApiVersions::VERSION
8
- s.authors = ["Erich Menge"]
9
- s.email = ["erich.menge@me.com"]
10
- s.homepage = "https://github.com/erichmenge/api-versions"
8
+ s.authors = ["Erich Menge", "David Celis"]
9
+ s.email = ["erich.menge@me.com", "me@davidcel.is"]
10
+ s.homepage = "https://github.com/EDMC/api-versions"
11
11
  s.summary = "api-versions helps manage your Rails app API endpoints."
12
12
  s.description = "api-versions helps manage your Rails app API endpoints."
13
13
 
14
- s.rubyforge_project = "api-versions"
15
-
16
14
  s.files = `git ls-files`.split("\n")
17
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -25,4 +23,5 @@ Gem::Specification.new do |s|
25
23
 
26
24
  s.add_development_dependency "rspec-rails", "~> 2.0"
27
25
  s.add_development_dependency 'ammeter', '0.2.5'
26
+ s.add_development_dependency "coveralls"
28
27
  end
@@ -5,9 +5,9 @@ module ApiVersions
5
5
  end
6
6
 
7
7
  def call(env)
8
- return @app.call(env) unless env['HTTP_ACCEPT']
9
-
10
- accepts = env['HTTP_ACCEPT'].split(',')
8
+ accept_string = env['HTTP_ACCEPT'] || ""
9
+ accepts = accept_string.split(',')
10
+ accepts.push("application/vnd.#{ApiVersions::VersionCheck.vendor_string}+json") unless accept_string.include?('application/vnd.')
11
11
  offset = 0
12
12
  accepts.dup.each_with_index do |accept, i|
13
13
  accept.strip!
@@ -1,8 +1,13 @@
1
1
  module ApiVersions
2
- MAJOR = 1
3
- MINOR = 2
4
- PATCH = 0
5
- PRE = nil
2
+ class Version
3
+ MAJOR = 1
4
+ MINOR = 2
5
+ PATCH = 1
6
6
 
7
- VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join '.'
7
+ def self.to_s
8
+ [MAJOR, MINOR, PATCH].join('.')
9
+ end
10
+ end
11
+
12
+ VERSION = Version.to_s
8
13
  end
@@ -1,2 +1,5 @@
1
- class Api::V3::Nests::NestedController
1
+ class Api::V3::Nests::NestedController < ActionController::Base
2
+ def new
3
+ render nothing: true
4
+ end
2
5
  end
@@ -15,6 +15,10 @@ Dummy::Application.routes.draw do
15
15
 
16
16
  version 3 do
17
17
  inherit from: 'v2'
18
+
19
+ namespace :nests do
20
+ resources :nested
21
+ end
18
22
  end
19
23
  end
20
24
 
@@ -24,16 +24,16 @@ describe ApiVersions::Middleware do
24
24
  response.last.should == "text/plain,application/json,application/vnd.myvendor+json;version=1,text/html,application/xml,application/vnd.myvendor+xml"
25
25
  end
26
26
 
27
- it "should tolerate a nil Accept header" do
27
+ it "should add a default vendor accept to a nil Accept header" do
28
28
  request = Rack::MockRequest.env_for("/", lint: true, fatal: true)
29
29
  response = described_class.new(app).call(request).last
30
- response.last.should_not be
30
+ response.last.should == "application/json,application/vnd.#{ApiVersions::VersionCheck.vendor_string}+json"
31
31
  end
32
32
 
33
- it "should tolerate an empty Accept header" do
33
+ it "should add a default vendor accept to an empty Accept header" do
34
34
  request = Rack::MockRequest.env_for("/", "HTTP_ACCEPT" => '', lint: true, fatal: true)
35
35
  response = described_class.new(app).call(request).last
36
- response.last.should == ""
36
+ response.last.should == "application/json,application/vnd.#{ApiVersions::VersionCheck.vendor_string}+json"
37
37
  end
38
38
  end
39
39
  end
@@ -55,13 +55,18 @@ describe 'API Routing' do
55
55
  get new_api_foo_path, nil, 'HTTP_ACCEPT' => 'application/vnd.myvendor+json;version=3'
56
56
  @controller.class.should == Api::V3::FooController
57
57
  end
58
+
59
+ it "should route to nested controllers" do
60
+ get new_api_nests_nested_path, nil, 'HTTP_ACCEPT' => 'application/vnd.myvendor+json;version=3'
61
+ @controller.class.should == Api::V3::Nests::NestedController
62
+ end
58
63
  end
59
64
 
60
65
  describe "Header syntax" do
61
66
  context "when valid" do
62
67
  after(:each) do
63
68
  get new_api_bar_path, nil, 'HTTP_ACCEPT' => @accept_string
64
- desired_format = /application\/.*\+\W*(?<format>\w+)\W*/.match(@accept_string)[:format]
69
+ desired_format = /application\/.*\+\s*(?<format>\w+)\s*/.match(@accept_string)[:format]
65
70
  response.content_type.should == "application/#{desired_format}"
66
71
  response.should be_success
67
72
  end
@@ -72,11 +77,11 @@ describe 'API Routing' do
72
77
  end
73
78
 
74
79
  it "should allow spaces before" do
75
- @accept_string = 'application/vnd.myvendor + xml ;version=1'
80
+ @accept_string = 'application/vnd.myvendor+xml ;version=1'
76
81
  end
77
82
 
78
83
  it "should allow spaces around" do
79
- @accept_string = 'application/vnd.myvendor + xml ; version=1'
84
+ @accept_string = 'application/vnd.myvendor+xml ; version=1'
80
85
  end
81
86
  end
82
87
 
@@ -104,7 +109,7 @@ describe 'API Routing' do
104
109
  end
105
110
 
106
111
  it "should allow spacing around" do
107
- @accept_string = 'application/vnd.myvendor +xml; version=1'
112
+ @accept_string = 'application/vnd.myvendor + xml; version=1'
108
113
  end
109
114
  end
110
115
  end
@@ -113,11 +118,6 @@ describe 'API Routing' do
113
118
  get new_api_bar_path, nil, 'HTTP_ACCEPT' => 'application/vnd.garbage+xml;version=1'
114
119
  response.status.should == 404
115
120
  end
116
-
117
- it "should not route when no header is specified" do
118
- get new_api_bar_path, nil
119
- response.status.should == 404
120
- end
121
121
  end
122
122
 
123
123
  describe 'paths' do
@@ -1,3 +1,9 @@
1
+ require 'coveralls'
2
+
3
+ Coveralls.wear! do
4
+ add_filter "/spec/"
5
+ end
6
+
1
7
  ENV["RAILS_ENV"] ||= 'test'
2
8
  require File.expand_path("../dummy/config/environment", __FILE__)
3
9
  require 'rspec/rails'
metadata CHANGED
@@ -1,55 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-versions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Menge
8
+ - David Celis
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-05-17 00:00:00.000000000 Z
12
+ date: 2015-02-23 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: actionpack
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - '>='
18
+ - - ">="
18
19
  - !ruby/object:Gem::Version
19
20
  version: '3.0'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - '>='
25
+ - - ">="
25
26
  - !ruby/object:Gem::Version
26
27
  version: '3.0'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: activesupport
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - '>='
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: '3.0'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - '>='
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: '3.0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rspec-rails
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ~>
46
+ - - "~>"
46
47
  - !ruby/object:Gem::Version
47
48
  version: '2.0'
48
49
  type: :development
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ~>
53
+ - - "~>"
53
54
  - !ruby/object:Gem::Version
54
55
  version: '2.0'
55
56
  - !ruby/object:Gem::Dependency
@@ -66,16 +67,31 @@ dependencies:
66
67
  - - '='
67
68
  - !ruby/object:Gem::Version
68
69
  version: 0.2.5
70
+ - !ruby/object:Gem::Dependency
71
+ name: coveralls
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
69
84
  description: api-versions helps manage your Rails app API endpoints.
70
85
  email:
71
86
  - erich.menge@me.com
87
+ - me@davidcel.is
72
88
  executables: []
73
89
  extensions: []
74
90
  extra_rdoc_files: []
75
91
  files:
76
- - .gitignore
77
- - .rspec
78
- - .travis.yml
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
79
95
  - Changes.md
80
96
  - Gemfile
81
97
  - License.txt
@@ -110,7 +126,7 @@ files:
110
126
  - spec/middleware_spec.rb
111
127
  - spec/routing_spec.rb
112
128
  - spec/spec_helper.rb
113
- homepage: https://github.com/erichmenge/api-versions
129
+ homepage: https://github.com/EDMC/api-versions
114
130
  licenses: []
115
131
  metadata: {}
116
132
  post_install_message:
@@ -119,17 +135,17 @@ require_paths:
119
135
  - lib
120
136
  required_ruby_version: !ruby/object:Gem::Requirement
121
137
  requirements:
122
- - - '>='
138
+ - - ">="
123
139
  - !ruby/object:Gem::Version
124
140
  version: '1.9'
125
141
  required_rubygems_version: !ruby/object:Gem::Requirement
126
142
  requirements:
127
- - - '>='
143
+ - - ">="
128
144
  - !ruby/object:Gem::Version
129
145
  version: '0'
130
146
  requirements: []
131
- rubyforge_project: api-versions
132
- rubygems_version: 2.0.2
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.5
133
149
  signing_key:
134
150
  specification_version: 4
135
151
  summary: api-versions helps manage your Rails app API endpoints.
@@ -154,3 +170,4 @@ test_files:
154
170
  - spec/middleware_spec.rb
155
171
  - spec/routing_spec.rb
156
172
  - spec/spec_helper.rb
173
+ has_rdoc: