versioncake 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +14 -14
- data/README.md +11 -0
- data/gemfiles/rails3.2.gemfile.lock +3 -3
- data/gemfiles/rails4.0.gemfile.lock +3 -3
- data/gemfiles/rails4.1.gemfile.lock +1 -1
- data/gemfiles/rails4.2.gemfile.lock +1 -1
- data/lib/generators/templates/versioncake.rb +9 -0
- data/lib/versioncake.rb +5 -0
- data/lib/versioncake/configuration.rb +16 -2
- data/lib/versioncake/rack/middleware.rb +12 -4
- data/lib/versioncake/response_strategy/base.rb +27 -0
- data/lib/versioncake/response_strategy/http_content_type_strategy.rb +12 -0
- data/lib/versioncake/response_strategy/http_header_strategy.rb +13 -0
- data/lib/versioncake/strategies/extraction_strategy.rb +6 -0
- data/lib/versioncake/version.rb +1 -1
- data/lib/versioncake/versioned_response_service.rb +13 -0
- data/spec/integration/controller/renders_controller_spec.rb +1 -1
- data/spec/integration/rack/middleware_regression_spec.rb +5 -3
- data/spec/test_app/config/initializers/versioncake.rb +2 -0
- data/spec/unit/configuration_spec.rb +11 -0
- data/spec/unit/middleware_spec.rb +60 -0
- data/spec/unit/response_strategy/base_spec.rb +16 -0
- data/spec/unit/response_strategy/http_content_type_strategy_spec.rb +27 -0
- data/spec/unit/response_strategy/http_header_strategy_spec.rb +18 -0
- data/spec/unit/strategies/extraction_strategy_spec.rb +7 -0
- data/spec/unit/versioned_response_service_spec.rb +30 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffbff82e08d0898e40a246fead162ecc1868740a
|
4
|
+
data.tar.gz: a7ad336abb131b5a8824ff02ae350dede3f7c24b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdaac92293782079e8bcadaf2badeb95e25024fb350883c71c68714af84dcff5821cc8cf075c8e21723c8efa917ac2560f2af3a1f5eef94d452cf7966976ddb8
|
7
|
+
data.tar.gz: 3b944387b2585102051a3921c8c9528957e275016dd113acd079d7489889a3064732427a2ee0ce55cec184aade173a1283f606432fbae9b359937a8e7bbc0f41
|
data/CHANGELOG.md
CHANGED
@@ -14,6 +14,20 @@ Deprecations:
|
|
14
14
|
|
15
15
|
* None
|
16
16
|
|
17
|
+
## 3.1.0 (Sept 29, 2015)
|
18
|
+
|
19
|
+
Bug Fixes:
|
20
|
+
|
21
|
+
* None
|
22
|
+
|
23
|
+
Enhancements:
|
24
|
+
|
25
|
+
* Respond with request version, support for either header or Content-Type (#39)
|
26
|
+
|
27
|
+
Deprecations:
|
28
|
+
|
29
|
+
* None
|
30
|
+
|
17
31
|
## 3.0.0 (Aug 3, 2015)
|
18
32
|
|
19
33
|
Bug Fixes:
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
versioncake (3.
|
4
|
+
versioncake (3.1.0)
|
5
5
|
actionpack (>= 3.2)
|
6
6
|
activesupport (>= 3.2)
|
7
7
|
railties (>= 3.2)
|
@@ -10,26 +10,26 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
actionpack (4.2.
|
14
|
-
actionview (= 4.2.
|
15
|
-
activesupport (= 4.2.
|
13
|
+
actionpack (4.2.4)
|
14
|
+
actionview (= 4.2.4)
|
15
|
+
activesupport (= 4.2.4)
|
16
16
|
rack (~> 1.6)
|
17
17
|
rack-test (~> 0.6.2)
|
18
18
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
19
19
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
20
|
-
actionview (4.2.
|
21
|
-
activesupport (= 4.2.
|
20
|
+
actionview (4.2.4)
|
21
|
+
activesupport (= 4.2.4)
|
22
22
|
builder (~> 3.1)
|
23
23
|
erubis (~> 2.7.0)
|
24
24
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
25
25
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
26
|
-
activesupport (4.2.
|
26
|
+
activesupport (4.2.4)
|
27
27
|
i18n (~> 0.7)
|
28
28
|
json (~> 1.7, >= 1.7.7)
|
29
29
|
minitest (~> 5.1)
|
30
30
|
thread_safe (~> 0.3, >= 0.3.4)
|
31
31
|
tzinfo (~> 1.1)
|
32
|
-
appraisal (2.0
|
32
|
+
appraisal (2.1.0)
|
33
33
|
bundler
|
34
34
|
rake
|
35
35
|
thor (>= 0.14.0)
|
@@ -49,11 +49,11 @@ GEM
|
|
49
49
|
domain_name (~> 0.5)
|
50
50
|
i18n (0.7.0)
|
51
51
|
json (1.8.3)
|
52
|
-
loofah (2.0.
|
52
|
+
loofah (2.0.3)
|
53
53
|
nokogiri (>= 1.5.9)
|
54
54
|
mime-types (2.6.1)
|
55
55
|
mini_portile (0.6.2)
|
56
|
-
minitest (5.
|
56
|
+
minitest (5.8.1)
|
57
57
|
netrc (0.10.3)
|
58
58
|
nokogiri (1.6.6.2)
|
59
59
|
mini_portile (~> 0.6.0)
|
@@ -62,15 +62,15 @@ GEM
|
|
62
62
|
rack (>= 1.0)
|
63
63
|
rails-deprecated_sanitizer (1.0.3)
|
64
64
|
activesupport (>= 4.2.0.alpha)
|
65
|
-
rails-dom-testing (1.0.
|
65
|
+
rails-dom-testing (1.0.7)
|
66
66
|
activesupport (>= 4.2.0.beta, < 5.0)
|
67
67
|
nokogiri (~> 1.6.0)
|
68
68
|
rails-deprecated_sanitizer (>= 1.0.1)
|
69
69
|
rails-html-sanitizer (1.0.2)
|
70
70
|
loofah (~> 2.0)
|
71
|
-
railties (4.2.
|
72
|
-
actionpack (= 4.2.
|
73
|
-
activesupport (= 4.2.
|
71
|
+
railties (4.2.4)
|
72
|
+
actionpack (= 4.2.4)
|
73
|
+
activesupport (= 4.2.4)
|
74
74
|
rake (>= 0.8.7)
|
75
75
|
thor (>= 0.18.1, < 2.0)
|
76
76
|
rake (10.4.2)
|
data/README.md
CHANGED
@@ -286,6 +286,13 @@ If you do not wish to use the magic mapping of the version number to templates i
|
|
286
286
|
config.rails_view_versioning = false
|
287
287
|
```
|
288
288
|
|
289
|
+
#### Response Version
|
290
|
+
|
291
|
+
If a client requests a specific version (or does not) and a version applies to the resource you can configure it to be in the response. Use the following configuration:
|
292
|
+
```ruby
|
293
|
+
config.response_strategy = [:http_content_type, :http_header]
|
294
|
+
```
|
295
|
+
|
289
296
|
### Version your views
|
290
297
|
|
291
298
|
When a client makes a request to your controller the latest version of the view will be rendered. The latest version is determined by naming the template or partial with a version number that you configured to support.
|
@@ -449,6 +456,10 @@ Thanks to all those who have helped make Version Cake really sweet:
|
|
449
456
|
- [RubyWeekly](http://rubyweekly.com/archive/119.html)
|
450
457
|
- [API building tools on Ruby Toolbox](https://www.ruby-toolbox.com/categories/API_Builders)
|
451
458
|
|
459
|
+
# Security issues?
|
460
|
+
|
461
|
+
If you think you have a security vulnerability, please submit the issue and the details to [https://hackerone.com/versioncake](https://hackerone.com/versioncake)
|
462
|
+
|
452
463
|
# Questions?
|
453
464
|
|
454
465
|
Create a bug/enhancement/question on github or contact [aantix](https://github.com/aantix) or [bwillis](https://github.com/bwillis) through github.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
versioncake (3.
|
4
|
+
versioncake (3.1.0)
|
5
5
|
actionpack (>= 3.2)
|
6
6
|
activesupport (>= 3.2)
|
7
7
|
railties (>= 3.2)
|
@@ -45,7 +45,7 @@ GEM
|
|
45
45
|
json (1.8.3)
|
46
46
|
mime-types (1.23)
|
47
47
|
multi_json (1.7.3)
|
48
|
-
power_assert (0.2.
|
48
|
+
power_assert (0.2.4)
|
49
49
|
rack (1.4.5)
|
50
50
|
rack-cache (1.2)
|
51
51
|
rack (>= 0.4)
|
@@ -94,7 +94,7 @@ GEM
|
|
94
94
|
multi_json (~> 1.0)
|
95
95
|
rack (~> 1.0)
|
96
96
|
tilt (~> 1.1, != 1.3.0)
|
97
|
-
test-unit (3.
|
97
|
+
test-unit (3.1.4)
|
98
98
|
power_assert
|
99
99
|
thor (0.18.1)
|
100
100
|
thread_safe (0.3.5)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
versioncake (3.
|
4
|
+
versioncake (3.1.0)
|
5
5
|
actionpack (>= 3.2)
|
6
6
|
activesupport (>= 3.2)
|
7
7
|
railties (>= 3.2)
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
mime-types (1.23)
|
41
41
|
minitest (4.7.5)
|
42
42
|
multi_json (1.7.7)
|
43
|
-
power_assert (0.2.
|
43
|
+
power_assert (0.2.4)
|
44
44
|
rack (1.5.2)
|
45
45
|
rack-test (0.6.2)
|
46
46
|
rack (>= 1.0)
|
@@ -76,7 +76,7 @@ GEM
|
|
76
76
|
multi_json (~> 1.0)
|
77
77
|
simplecov-html (~> 0.7.1)
|
78
78
|
simplecov-html (0.7.1)
|
79
|
-
test-unit (3.
|
79
|
+
test-unit (3.1.4)
|
80
80
|
power_assert
|
81
81
|
thor (0.18.1)
|
82
82
|
thread_safe (0.1.0)
|
@@ -37,4 +37,13 @@ VersionCake.setup do |config|
|
|
37
37
|
|
38
38
|
# Enable Rails versioned filename mapping
|
39
39
|
# config.rails_view_versioning = true
|
40
|
+
|
41
|
+
# Response Strategies
|
42
|
+
# Define how (if at all) to include the version in the response. Similar to how to retrieve the
|
43
|
+
# version, you can set where it will be in the response. For example, the `http_header_strategy`
|
44
|
+
# will include it the response header under the key configured in `config.version_key`.
|
45
|
+
#
|
46
|
+
# Defaults to none
|
47
|
+
#
|
48
|
+
# config.response_strategy = [] # [:http_content_type, :http_header]
|
40
49
|
end
|
data/lib/versioncake.rb
CHANGED
@@ -6,12 +6,17 @@ require 'versioncake/strategies/path_parameter_strategy'
|
|
6
6
|
require 'versioncake/strategies/request_parameter_strategy'
|
7
7
|
require 'versioncake/strategies/custom_strategy'
|
8
8
|
|
9
|
+
require 'versioncake/response_strategy/base'
|
10
|
+
require 'versioncake/response_strategy/http_header_strategy'
|
11
|
+
require 'versioncake/response_strategy/http_content_type_strategy'
|
12
|
+
|
9
13
|
require 'versioncake/exceptions'
|
10
14
|
require 'versioncake/configuration'
|
11
15
|
require 'versioncake/versioned_request'
|
12
16
|
require 'versioncake/version_checker'
|
13
17
|
require 'versioncake/version_context'
|
14
18
|
require 'versioncake/version_context_service'
|
19
|
+
require 'versioncake/versioned_response_service'
|
15
20
|
require 'versioncake/versioned_resource'
|
16
21
|
require 'versioncake/rack/middleware'
|
17
22
|
require 'versioncake/cli'
|
@@ -7,7 +7,7 @@ module VersionCake
|
|
7
7
|
SUPPORTED_VERSIONS_DEFAULT = (1..10)
|
8
8
|
VERSION_KEY_DEFAULT = 'api_version'
|
9
9
|
|
10
|
-
attr_reader :extraction_strategies, :supported_version_numbers, :versioned_resources
|
10
|
+
attr_reader :extraction_strategies, :response_strategies, :supported_version_numbers, :versioned_resources
|
11
11
|
attr_accessor :missing_version, :version_key, :rails_view_versioning
|
12
12
|
|
13
13
|
def initialize
|
@@ -15,7 +15,14 @@ module VersionCake
|
|
15
15
|
@version_key = VERSION_KEY_DEFAULT
|
16
16
|
@rails_view_versioning = true
|
17
17
|
self.supported_version_numbers = SUPPORTED_VERSIONS_DEFAULT
|
18
|
-
self.extraction_strategy =
|
18
|
+
self.extraction_strategy = [
|
19
|
+
:http_accept_parameter,
|
20
|
+
:http_header,
|
21
|
+
:request_parameter,
|
22
|
+
:path_parameter,
|
23
|
+
:query_parameter
|
24
|
+
]
|
25
|
+
self.response_strategy = []
|
19
26
|
end
|
20
27
|
|
21
28
|
def extraction_strategy=(val)
|
@@ -25,6 +32,13 @@ module VersionCake
|
|
25
32
|
end
|
26
33
|
end
|
27
34
|
|
35
|
+
def response_strategy=(val)
|
36
|
+
@response_strategies = []
|
37
|
+
Array.wrap(val).each do |configured_strategy|
|
38
|
+
@response_strategies << VersionCake::ResponseStrategy::Base.lookup(configured_strategy)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
def supported_version_numbers=(val)
|
29
43
|
@supported_version_numbers = val.respond_to?(:to_a) ? val.to_a : Array.wrap(val)
|
30
44
|
@supported_version_numbers.sort!.reverse!
|
@@ -2,18 +2,26 @@ module VersionCake
|
|
2
2
|
module Rack
|
3
3
|
class Middleware
|
4
4
|
|
5
|
-
def initialize(app)
|
5
|
+
def initialize(app, config=VersionCake.config)
|
6
6
|
@app = app
|
7
|
-
@version_service = VersionCake::VersionContextService.new(
|
7
|
+
@version_service = VersionCake::VersionContextService.new(config)
|
8
|
+
@response_service = VersionCake::VersionedResponseService.new(config)
|
9
|
+
@config = config
|
8
10
|
end
|
9
11
|
|
10
12
|
def call(env)
|
11
13
|
request = ::Rack::Request.new env
|
12
14
|
if context = @version_service.create_context_from_request(request)
|
13
15
|
env['versioncake.context'] = context
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
+
status, headers, response = @app.call(env)
|
18
|
+
|
19
|
+
@response_service.inject_version(context, status, headers, response)
|
20
|
+
|
21
|
+
[status, headers, response]
|
22
|
+
else
|
23
|
+
@app.call(env)
|
24
|
+
end
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module VersionCake
|
2
|
+
module ResponseStrategy
|
3
|
+
class Base
|
4
|
+
def execute(_context, _status, _headers, _response)
|
5
|
+
raise Exception, "ResponseStrategy requires execute to be implemented"
|
6
|
+
end
|
7
|
+
|
8
|
+
def version_key
|
9
|
+
VersionCake.config.version_key
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.lookup(strategy)
|
13
|
+
case strategy
|
14
|
+
when String, Symbol
|
15
|
+
strategy_name = "#{strategy}_strategy".camelize
|
16
|
+
begin
|
17
|
+
VersionCake::ResponseStrategy.const_get(strategy_name).new
|
18
|
+
rescue
|
19
|
+
raise Exception, "Unknown VersionCake response strategy #{strategy_name}"
|
20
|
+
end
|
21
|
+
else
|
22
|
+
raise Exception, "Invalid response strategy"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module VersionCake
|
2
|
+
module ResponseStrategy
|
3
|
+
class HttpContentTypeStrategy < Base
|
4
|
+
def execute(context, _status, headers, _response)
|
5
|
+
return if headers['Content-Type'].nil?
|
6
|
+
|
7
|
+
headers['Content-Type'] << ';' unless headers['Content-Type'].end_with? ';'
|
8
|
+
headers['Content-Type'] << " #{version_key}=#{context.version.to_s}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module VersionCake
|
2
|
+
module ResponseStrategy
|
3
|
+
class HttpHeaderStrategy < Base
|
4
|
+
def execute(context, _status, headers, _response)
|
5
|
+
headers[header_key] = context.version.to_s
|
6
|
+
end
|
7
|
+
|
8
|
+
def header_key
|
9
|
+
version_key.gsub('_', '-')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -27,6 +27,12 @@ module VersionCake
|
|
27
27
|
raise Exception, "ExtractionStrategy requires execute to be implemented"
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.list(*strategies)
|
31
|
+
strategies.map do |strategy|
|
32
|
+
lookup(strategy)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
30
36
|
def self.lookup(strategy)
|
31
37
|
case strategy
|
32
38
|
when String, Symbol
|
data/lib/versioncake/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
module VersionCake
|
2
|
+
class VersionedResponseService
|
3
|
+
def initialize(config)
|
4
|
+
@strategies = config.response_strategies
|
5
|
+
end
|
6
|
+
|
7
|
+
def inject_version(versioned_context, status, headers, response)
|
8
|
+
@strategies.each do |strategy|
|
9
|
+
strategy.execute(versioned_context, status, headers, response)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -18,7 +18,7 @@ describe RendersController, type: :controller do
|
|
18
18
|
it { expect(response_body).to eq 'template v1' }
|
19
19
|
end
|
20
20
|
|
21
|
-
context '
|
21
|
+
context 'when explicitly requesting the latest version' do
|
22
22
|
let(:request_version) { 5 }
|
23
23
|
|
24
24
|
it { expect(controller.request_version).to eq 5 }
|
@@ -4,8 +4,10 @@ require 'yaml'
|
|
4
4
|
describe VersionCake::Rack::Middleware do
|
5
5
|
let(:app) do
|
6
6
|
rack = Rack::Builder.new do
|
7
|
-
|
8
|
-
|
7
|
+
config = VersionCake::Configuration.new
|
8
|
+
config.resources { |r| r.resource %r{.*}, [], [], (1..5) }
|
9
|
+
use VersionCake::Rack::Middleware, config
|
10
|
+
run lambda { |env| [ 200, {},[ env['versioncake.context'].version ] ] }
|
9
11
|
end
|
10
12
|
Rack::MockRequest.new(rack)
|
11
13
|
end
|
@@ -23,7 +25,7 @@ describe VersionCake::Rack::Middleware do
|
|
23
25
|
|
24
26
|
it "test yml test cases" do
|
25
27
|
begin
|
26
|
-
response = app.request(method, '/renders', headers.merge(params: params))
|
28
|
+
_response_status, _response_headers, response = app.request(method, '/renders', headers.merge(params: params))
|
27
29
|
expect(response.body).to(eq(test_response), custom_message(headers, params, method, response.body, test_response))
|
28
30
|
rescue => e
|
29
31
|
raise custom_message(headers, params, method, response.body, test_response) + ", but it failed with an exception '#{e.message}'"
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe VersionCake::Configuration do
|
4
|
+
let(:supported_versions) { }
|
4
5
|
subject(:config) do
|
5
6
|
config = described_class.new
|
6
7
|
if supported_versions
|
@@ -58,4 +59,14 @@ describe VersionCake::Configuration do
|
|
58
59
|
|
59
60
|
it { expect(config.latest_version).to eq 54 }
|
60
61
|
end
|
62
|
+
|
63
|
+
context 'by default' do
|
64
|
+
it 'has all extraction strategies' do
|
65
|
+
expect(config.extraction_strategies.map(&:class)).to match_array(
|
66
|
+
VersionCake::ExtractionStrategy.list(
|
67
|
+
:http_accept_parameter, :http_header, :request_parameter, :path_parameter, :query_parameter
|
68
|
+
).map(&:class)
|
69
|
+
)
|
70
|
+
end
|
71
|
+
end
|
61
72
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack'
|
3
|
+
|
4
|
+
describe VersionCake::Rack::Middleware do
|
5
|
+
let(:response_strategy) { nil }
|
6
|
+
let(:config) do
|
7
|
+
VersionCake::Configuration.new.tap do |config|
|
8
|
+
config.extraction_strategy = [:http_header]
|
9
|
+
config.response_strategy = response_strategy
|
10
|
+
config.resources do |resource_config|
|
11
|
+
resource_config.resource %r{.*}, [], [], (1..5)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
let(:upstream_headers) { {} }
|
16
|
+
let(:middleware) do
|
17
|
+
VersionCake::Rack::Middleware.new(
|
18
|
+
double(call: [nil, upstream_headers, nil] ),
|
19
|
+
config
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
context '#call' do
|
24
|
+
let(:env) do
|
25
|
+
{
|
26
|
+
'SCRIPT_NAME' => '',
|
27
|
+
'PATH_INFO' => '',
|
28
|
+
'HTTP_API_VERSION' => '1'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
subject { middleware.call(env) }
|
33
|
+
let(:response_headers) { subject[1] }
|
34
|
+
|
35
|
+
context 'when response_strategy is http_header' do
|
36
|
+
let(:response_strategy) { [:http_header] }
|
37
|
+
|
38
|
+
it 'sets the version in the response header' do
|
39
|
+
expect(response_headers['api-version']).to eq '1'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when response_strategy is http_content_type' do
|
44
|
+
let(:response_strategy) { [:http_content_type] }
|
45
|
+
let(:upstream_headers) { { 'Content-Type' => 'application/vnd.api+json; charset=utf-8;' } }
|
46
|
+
|
47
|
+
it 'sets the version in the content type' do
|
48
|
+
expect(response_headers['Content-Type']).to match 'application/vnd.api+json; charset=utf-8; api_version=1'
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with a simpler content type' do
|
52
|
+
let(:upstream_headers) { { 'Content-Type' => 'application/json' } }
|
53
|
+
|
54
|
+
it 'sets the version in the content type' do
|
55
|
+
expect(response_headers['Content-Type']).to match 'application/json; api_version=1'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VersionCake::ResponseStrategy::Base do
|
4
|
+
describe '.lookup' do
|
5
|
+
let(:strategy) { :http_content_type }
|
6
|
+
subject(:found_strategy) { VersionCake::ResponseStrategy::Base.lookup(strategy) }
|
7
|
+
|
8
|
+
it { expect(found_strategy.class).to eq VersionCake::ResponseStrategy::HttpContentTypeStrategy }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#execute' do
|
12
|
+
subject(:execute) { VersionCake::ResponseStrategy::Base.new.execute(nil,nil,nil,nil) }
|
13
|
+
|
14
|
+
it { expect { execute }.to raise_error Exception }
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VersionCake::ResponseStrategy::HttpContentTypeStrategy do
|
4
|
+
describe '#execute' do
|
5
|
+
let(:headers) { { 'Content-Type' => 'application/json' } }
|
6
|
+
let(:context) { double('content', version: 4) }
|
7
|
+
before do
|
8
|
+
VersionCake::ResponseStrategy::HttpContentTypeStrategy.new.execute(
|
9
|
+
context, nil, headers, nil
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
it { expect(headers['Content-Type']).to eq 'application/json; api_version=4' }
|
14
|
+
|
15
|
+
context 'for a header that ends in a semi colon' do
|
16
|
+
let(:headers) { { 'Content-Type' => 'application/vnd.api+json; charset=utf-8;' } }
|
17
|
+
|
18
|
+
it { expect(headers['Content-Type']).to eq 'application/vnd.api+json; charset=utf-8; api_version=4' }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when there is no content type' do
|
22
|
+
let(:headers) { {} }
|
23
|
+
|
24
|
+
it { expect(headers.empty?).to eq true }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VersionCake::ResponseStrategy::HttpHeaderStrategy do
|
4
|
+
describe '#execute' do
|
5
|
+
let(:headers) { { } }
|
6
|
+
let(:context) { double('content', version: 8) }
|
7
|
+
before do
|
8
|
+
VersionCake::ResponseStrategy::HttpHeaderStrategy.new.execute(
|
9
|
+
context, nil, headers, nil
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
it do
|
14
|
+
expect(headers.keys).to include 'api-version'
|
15
|
+
expect(headers['api-version']).to eq '8'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -68,4 +68,11 @@ describe VersionCake::ExtractionStrategy do
|
|
68
68
|
VersionCake::ExtractionStrategy.lookup(:fake_extraction)
|
69
69
|
end.to raise_error(Exception)
|
70
70
|
end
|
71
|
+
|
72
|
+
describe '.list' do
|
73
|
+
let(:strategies) { :http_header }
|
74
|
+
subject { VersionCake::ExtractionStrategy.list(strategies) }
|
75
|
+
|
76
|
+
it { expect(subject.map(&:class)).to match_array VersionCake::HttpHeaderStrategy }
|
77
|
+
end
|
71
78
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VersionCake::VersionedResponseService do
|
4
|
+
|
5
|
+
let(:config) { double(response_strategies: [VersionCake::ResponseStrategy::HttpHeaderStrategy.new]) }
|
6
|
+
let(:service) { described_class.new(config)}
|
7
|
+
|
8
|
+
describe '#inject_version' do
|
9
|
+
let(:context) { double('content', version: 2) }
|
10
|
+
let(:headers) { { } }
|
11
|
+
|
12
|
+
before { service.inject_version(context, nil, headers, nil) }
|
13
|
+
|
14
|
+
it { expect(headers['api-version']).to eq '2' }
|
15
|
+
|
16
|
+
context 'when configured with multiple response strategies' do
|
17
|
+
let(:headers) { { 'Content-Type' => 'application/vnd.api+json; charset=utf-8;' } }
|
18
|
+
|
19
|
+
let(:config) do
|
20
|
+
double(response_strategies: [
|
21
|
+
VersionCake::ResponseStrategy::HttpHeaderStrategy.new,
|
22
|
+
VersionCake::ResponseStrategy::HttpContentTypeStrategy.new
|
23
|
+
])
|
24
|
+
end
|
25
|
+
|
26
|
+
it { expect(headers['Content-Type']).to eq 'application/vnd.api+json; charset=utf-8; api_version=2' }
|
27
|
+
it { expect(headers['api-version']).to eq '2' }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: versioncake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Jones
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -176,6 +176,9 @@ files:
|
|
176
176
|
- lib/versioncake/engine.rb
|
177
177
|
- lib/versioncake/exceptions.rb
|
178
178
|
- lib/versioncake/rack/middleware.rb
|
179
|
+
- lib/versioncake/response_strategy/base.rb
|
180
|
+
- lib/versioncake/response_strategy/http_content_type_strategy.rb
|
181
|
+
- lib/versioncake/response_strategy/http_header_strategy.rb
|
179
182
|
- lib/versioncake/strategies/custom_strategy.rb
|
180
183
|
- lib/versioncake/strategies/extraction_strategy.rb
|
181
184
|
- lib/versioncake/strategies/http_accept_parameter_strategy.rb
|
@@ -190,6 +193,7 @@ files:
|
|
190
193
|
- lib/versioncake/version_context_service.rb
|
191
194
|
- lib/versioncake/versioned_request.rb
|
192
195
|
- lib/versioncake/versioned_resource.rb
|
196
|
+
- lib/versioncake/versioned_response_service.rb
|
193
197
|
- lib/versioncake/view_additions.rb
|
194
198
|
- spec/fixtures/partials/_versioned.erb
|
195
199
|
- spec/fixtures/partials/_versioned.v1.erb
|
@@ -228,6 +232,10 @@ files:
|
|
228
232
|
- spec/test_app/script/rails
|
229
233
|
- spec/unit/cli_spec.rb
|
230
234
|
- spec/unit/configuration_spec.rb
|
235
|
+
- spec/unit/middleware_spec.rb
|
236
|
+
- spec/unit/response_strategy/base_spec.rb
|
237
|
+
- spec/unit/response_strategy/http_content_type_strategy_spec.rb
|
238
|
+
- spec/unit/response_strategy/http_header_strategy_spec.rb
|
231
239
|
- spec/unit/strategies/extraction_strategy_spec.rb
|
232
240
|
- spec/unit/strategies/http_accept_parameter_strategy_spec.rb
|
233
241
|
- spec/unit/strategies/http_header_strategy_spec.rb
|
@@ -239,6 +247,7 @@ files:
|
|
239
247
|
- spec/unit/version_context_spec.rb
|
240
248
|
- spec/unit/versioned_request_spec.rb
|
241
249
|
- spec/unit/versioned_resource_spec.rb
|
250
|
+
- spec/unit/versioned_response_service_spec.rb
|
242
251
|
- versioncake.gemspec
|
243
252
|
homepage: http://bwillis.github.io/versioncake
|
244
253
|
licenses:
|
@@ -260,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
260
269
|
version: '0'
|
261
270
|
requirements: []
|
262
271
|
rubyforge_project:
|
263
|
-
rubygems_version: 2.4.
|
272
|
+
rubygems_version: 2.4.8
|
264
273
|
signing_key:
|
265
274
|
specification_version: 4
|
266
275
|
summary: Easily render versions of your rails views.
|