versioncake 3.1.0 → 3.2.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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/CHANGELOG.md +18 -1
- data/Gemfile.lock +40 -51
- data/README.md +3 -3
- data/gemfiles/rails3.2.gemfile.lock +1 -1
- data/gemfiles/rails4.0.gemfile.lock +1 -1
- data/gemfiles/rails4.1.gemfile.lock +1 -1
- data/gemfiles/rails4.2.gemfile.lock +1 -1
- data/lib/generators/templates/versioncake.rb +12 -2
- data/lib/versioncake/configuration.rb +16 -2
- data/lib/versioncake/controller_additions.rb +27 -9
- data/lib/versioncake/strategies/extraction_strategy.rb +5 -1
- data/lib/versioncake/test_helpers.rb +3 -3
- data/lib/versioncake/version.rb +1 -1
- data/lib/versioncake/version_context.rb +4 -3
- data/lib/versioncake/version_context_service.rb +8 -2
- data/lib/versioncake/versioned_resource.rb +5 -1
- data/spec/integration/controller/renders_controller_spec.rb +27 -4
- data/spec/integration/rack/middleware_regression_spec.rb +25 -7
- data/spec/unit/configuration_spec.rb +16 -0
- data/spec/unit/version_context_service_spec.rb +64 -1
- data/spec/unit/version_context_spec.rb +5 -4
- data/spec/unit/versioned_resource_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f84afe2a8666bd9519a29fcc2e1a586a112cc0af
|
|
4
|
+
data.tar.gz: 6099b97d3dd4d7c03079adda4023ba0f8cdf73ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a41ea97ca34301cdf0ad20e7a3697333e85dc51b07474af15cc5fe92bcc7816ea838303c473979260686b414846896599c717ee3b33e1acfb9e6be413069eb8e
|
|
7
|
+
data.tar.gz: 8fb2a7b282d56c12ebef07c948a6dc9516d431164a1363b1827e7d28885894af788945e3eed8116fdbbdcb95c395834bcda796c44e50d7797866d22a640474c6
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## Unreleased Changes
|
|
2
2
|
|
|
3
|
-
[Full Changelog](https://github.com/bwillis/versioncake/compare/v3.
|
|
3
|
+
[Full Changelog](https://github.com/bwillis/versioncake/compare/v3.2...master)
|
|
4
4
|
|
|
5
5
|
Bug Fixes:
|
|
6
6
|
|
|
@@ -14,6 +14,23 @@ Deprecations:
|
|
|
14
14
|
|
|
15
15
|
* None
|
|
16
16
|
|
|
17
|
+
## 3.2.0 (Aug 8, 2015)
|
|
18
|
+
|
|
19
|
+
Bug Fixes:
|
|
20
|
+
|
|
21
|
+
* Deprecated versions would not render properly (#47)
|
|
22
|
+
* Blank `api_version` does not raise `MissingVersionError` (#50)
|
|
23
|
+
* Fix `set_version` not overriding version number (#54)
|
|
24
|
+
* Fix api only Rails app exception (#55)
|
|
25
|
+
|
|
26
|
+
Enhancements:
|
|
27
|
+
|
|
28
|
+
* Support missing version as unversioned template (#43)
|
|
29
|
+
|
|
30
|
+
Deprecations:
|
|
31
|
+
|
|
32
|
+
* None
|
|
33
|
+
|
|
17
34
|
## 3.1.0 (Sept 29, 2015)
|
|
18
35
|
|
|
19
36
|
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.2.0)
|
|
5
5
|
actionpack (>= 3.2)
|
|
6
6
|
activesupport (>= 3.2)
|
|
7
7
|
railties (>= 3.2)
|
|
@@ -10,20 +10,20 @@ 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.6)
|
|
14
|
+
actionview (= 4.2.6)
|
|
15
|
+
activesupport (= 4.2.6)
|
|
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.6)
|
|
21
|
+
activesupport (= 4.2.6)
|
|
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.6)
|
|
27
27
|
i18n (~> 0.7)
|
|
28
28
|
json (~> 1.7, >= 1.7.7)
|
|
29
29
|
minitest (~> 5.1)
|
|
@@ -34,29 +34,25 @@ GEM
|
|
|
34
34
|
rake
|
|
35
35
|
thor (>= 0.14.0)
|
|
36
36
|
builder (3.2.2)
|
|
37
|
-
coveralls (0.8.
|
|
37
|
+
coveralls (0.8.13)
|
|
38
38
|
json (~> 1.8)
|
|
39
|
-
|
|
40
|
-
simplecov (~> 0.10.0)
|
|
39
|
+
simplecov (~> 0.11.0)
|
|
41
40
|
term-ansicolor (~> 1.3)
|
|
42
41
|
thor (~> 0.19.1)
|
|
42
|
+
tins (~> 1.6.0)
|
|
43
43
|
diff-lcs (1.2.5)
|
|
44
44
|
docile (1.1.5)
|
|
45
|
-
domain_name (0.5.24)
|
|
46
|
-
unf (>= 0.0.5, < 1.0.0)
|
|
47
45
|
erubis (2.7.0)
|
|
48
|
-
http-cookie (1.0.2)
|
|
49
|
-
domain_name (~> 0.5)
|
|
50
46
|
i18n (0.7.0)
|
|
51
47
|
json (1.8.3)
|
|
52
48
|
loofah (2.0.3)
|
|
53
49
|
nokogiri (>= 1.5.9)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
mini_portile2 (2.1.0)
|
|
51
|
+
minitest (5.9.0)
|
|
52
|
+
nokogiri (1.6.8)
|
|
53
|
+
mini_portile2 (~> 2.1.0)
|
|
54
|
+
pkg-config (~> 1.1.7)
|
|
55
|
+
pkg-config (1.1.7)
|
|
60
56
|
rack (1.6.4)
|
|
61
57
|
rack-test (0.6.3)
|
|
62
58
|
rack (>= 1.0)
|
|
@@ -66,40 +62,36 @@ GEM
|
|
|
66
62
|
activesupport (>= 4.2.0.beta, < 5.0)
|
|
67
63
|
nokogiri (~> 1.6.0)
|
|
68
64
|
rails-deprecated_sanitizer (>= 1.0.1)
|
|
69
|
-
rails-html-sanitizer (1.0.
|
|
65
|
+
rails-html-sanitizer (1.0.3)
|
|
70
66
|
loofah (~> 2.0)
|
|
71
|
-
railties (4.2.
|
|
72
|
-
actionpack (= 4.2.
|
|
73
|
-
activesupport (= 4.2.
|
|
67
|
+
railties (4.2.6)
|
|
68
|
+
actionpack (= 4.2.6)
|
|
69
|
+
activesupport (= 4.2.6)
|
|
74
70
|
rake (>= 0.8.7)
|
|
75
71
|
thor (>= 0.18.1, < 2.0)
|
|
76
|
-
rake (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
rspec (3.
|
|
82
|
-
rspec-
|
|
83
|
-
|
|
84
|
-
rspec-mocks (~> 3.3.0)
|
|
85
|
-
rspec-core (3.3.2)
|
|
86
|
-
rspec-support (~> 3.3.0)
|
|
87
|
-
rspec-expectations (3.3.1)
|
|
72
|
+
rake (11.2.2)
|
|
73
|
+
rspec (3.4.0)
|
|
74
|
+
rspec-core (~> 3.4.0)
|
|
75
|
+
rspec-expectations (~> 3.4.0)
|
|
76
|
+
rspec-mocks (~> 3.4.0)
|
|
77
|
+
rspec-core (3.4.4)
|
|
78
|
+
rspec-support (~> 3.4.0)
|
|
79
|
+
rspec-expectations (3.4.0)
|
|
88
80
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
89
|
-
rspec-support (~> 3.
|
|
90
|
-
rspec-mocks (3.
|
|
81
|
+
rspec-support (~> 3.4.0)
|
|
82
|
+
rspec-mocks (3.4.1)
|
|
91
83
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
92
|
-
rspec-support (~> 3.
|
|
93
|
-
rspec-rails (3.
|
|
84
|
+
rspec-support (~> 3.4.0)
|
|
85
|
+
rspec-rails (3.4.2)
|
|
94
86
|
actionpack (>= 3.0, < 4.3)
|
|
95
87
|
activesupport (>= 3.0, < 4.3)
|
|
96
88
|
railties (>= 3.0, < 4.3)
|
|
97
|
-
rspec-core (~> 3.
|
|
98
|
-
rspec-expectations (~> 3.
|
|
99
|
-
rspec-mocks (~> 3.
|
|
100
|
-
rspec-support (~> 3.
|
|
101
|
-
rspec-support (3.
|
|
102
|
-
simplecov (0.
|
|
89
|
+
rspec-core (~> 3.4.0)
|
|
90
|
+
rspec-expectations (~> 3.4.0)
|
|
91
|
+
rspec-mocks (~> 3.4.0)
|
|
92
|
+
rspec-support (~> 3.4.0)
|
|
93
|
+
rspec-support (3.4.1)
|
|
94
|
+
simplecov (0.11.2)
|
|
103
95
|
docile (~> 1.1.0)
|
|
104
96
|
json (~> 1.8)
|
|
105
97
|
simplecov-html (~> 0.10.0)
|
|
@@ -108,12 +100,9 @@ GEM
|
|
|
108
100
|
tins (~> 1.0)
|
|
109
101
|
thor (0.19.1)
|
|
110
102
|
thread_safe (0.3.5)
|
|
111
|
-
tins (1.
|
|
103
|
+
tins (1.6.0)
|
|
112
104
|
tzinfo (1.2.2)
|
|
113
105
|
thread_safe (~> 0.1)
|
|
114
|
-
unf (0.1.4)
|
|
115
|
-
unf_ext
|
|
116
|
-
unf_ext (0.0.7.1)
|
|
117
106
|
|
|
118
107
|
PLATFORMS
|
|
119
108
|
ruby
|
|
@@ -127,4 +116,4 @@ DEPENDENCIES
|
|
|
127
116
|
versioncake!
|
|
128
117
|
|
|
129
118
|
BUNDLED WITH
|
|
130
|
-
1.
|
|
119
|
+
1.12.5
|
data/README.md
CHANGED
|
@@ -388,10 +388,10 @@ end
|
|
|
388
388
|
|
|
389
389
|
You can also test a specific version through a specific strategy such query_parameter or request_parameter strategies (configured in test environment) like so:
|
|
390
390
|
```ruby
|
|
391
|
-
# test/
|
|
391
|
+
# test/integration/renders_integration_test.rb#L47
|
|
392
392
|
test "render version 1 of the partial based on the parameter _api_version" do
|
|
393
|
-
get
|
|
394
|
-
assert_equal
|
|
393
|
+
get renders_path("api_version" => "1")
|
|
394
|
+
assert_equal "index.html.v1.erb", @response.body
|
|
395
395
|
end
|
|
396
396
|
```
|
|
397
397
|
|
|
@@ -29,8 +29,18 @@ VersionCake.setup do |config|
|
|
|
29
29
|
# ```
|
|
30
30
|
# config.extraction_strategy = [:http_accept_parameter, :http_header, :request_parameter, :path_parameter, :query_parameter]
|
|
31
31
|
|
|
32
|
-
# Version
|
|
33
|
-
|
|
32
|
+
# Missing Version
|
|
33
|
+
# What to use when no version in present in the request.
|
|
34
|
+
#
|
|
35
|
+
# Defaults to `:unversioned_template`
|
|
36
|
+
#
|
|
37
|
+
# Integer value:
|
|
38
|
+
# the version number to use
|
|
39
|
+
#
|
|
40
|
+
# `:unversioned_template` value:
|
|
41
|
+
# If you are using `rails_view_versioning` this will render the "base template" aka
|
|
42
|
+
# the template without a version number.
|
|
43
|
+
# config.missing_version = :unversioned_template
|
|
34
44
|
|
|
35
45
|
# Set the version key that clients will send example: `API-VERSION: 5`, api_version=2
|
|
36
46
|
# config.version_key = 'api_version'
|
|
@@ -7,13 +7,16 @@ module VersionCake
|
|
|
7
7
|
SUPPORTED_VERSIONS_DEFAULT = (1..10)
|
|
8
8
|
VERSION_KEY_DEFAULT = 'api_version'
|
|
9
9
|
|
|
10
|
-
attr_reader :extraction_strategies, :response_strategies, :supported_version_numbers,
|
|
10
|
+
attr_reader :extraction_strategies, :response_strategies, :supported_version_numbers,
|
|
11
|
+
:versioned_resources, :default_version, :missing_version_use_unversioned_template
|
|
11
12
|
attr_accessor :missing_version, :version_key, :rails_view_versioning
|
|
12
13
|
|
|
13
14
|
def initialize
|
|
14
15
|
@versioned_resources = []
|
|
15
16
|
@version_key = VERSION_KEY_DEFAULT
|
|
16
17
|
@rails_view_versioning = true
|
|
18
|
+
@missing_version_use_unversioned_template = true
|
|
19
|
+
@default_version = nil
|
|
17
20
|
self.supported_version_numbers = SUPPORTED_VERSIONS_DEFAULT
|
|
18
21
|
self.extraction_strategy = [
|
|
19
22
|
:http_accept_parameter,
|
|
@@ -25,6 +28,17 @@ module VersionCake
|
|
|
25
28
|
self.response_strategy = []
|
|
26
29
|
end
|
|
27
30
|
|
|
31
|
+
def missing_version=(val)
|
|
32
|
+
@missing_version = val
|
|
33
|
+
if @missing_version == :unversioned_template
|
|
34
|
+
@missing_version_use_unversioned_template = true
|
|
35
|
+
@default_version = nil
|
|
36
|
+
else
|
|
37
|
+
@missing_version_use_unversioned_template = false
|
|
38
|
+
@default_version = val
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
28
42
|
def extraction_strategy=(val)
|
|
29
43
|
@extraction_strategies = []
|
|
30
44
|
Array.wrap(val).each do |configured_strategy|
|
|
@@ -76,4 +90,4 @@ module VersionCake
|
|
|
76
90
|
@resources << VersionCake::VersionedResource.new(regex, obsolete, unsupported, supported)
|
|
77
91
|
end
|
|
78
92
|
end
|
|
79
|
-
end
|
|
93
|
+
end
|
|
@@ -45,23 +45,41 @@ module VersionCake
|
|
|
45
45
|
# @return No explicit return, but several attributes are exposed
|
|
46
46
|
def check_version!(override_version=nil)
|
|
47
47
|
return unless version_context
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
|
|
49
|
+
check_for_version_errors!(version_context.result)
|
|
50
|
+
configure_rails_view_versioning(version_context)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def check_for_version_errors!(result)
|
|
54
|
+
case result
|
|
55
|
+
when :version_invalid, :version_too_high, :version_too_low, :unknown
|
|
56
|
+
raise UnsupportedVersionError.new('Unsupported version error')
|
|
57
|
+
when :obsolete
|
|
58
|
+
raise ObsoleteVersionError.new('The version given is obsolete')
|
|
59
|
+
when :no_version
|
|
60
|
+
unless VersionCake.config.missing_version_use_unversioned_template
|
|
55
61
|
raise MissingVersionError.new('No version was given')
|
|
62
|
+
end
|
|
56
63
|
end
|
|
64
|
+
end
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
def configure_rails_view_versioning(version_context)
|
|
67
|
+
return unless VersionCake.config.rails_view_versioning
|
|
68
|
+
|
|
69
|
+
if version_context.result == :no_version &&
|
|
70
|
+
VersionCake.config.missing_version_use_unversioned_template
|
|
71
|
+
lookup_context.versions = nil
|
|
72
|
+
else
|
|
73
|
+
lookup_context.versions = version_context.available_versions.map { |n| :"v#{n}" }
|
|
60
74
|
end
|
|
61
75
|
end
|
|
62
76
|
|
|
63
77
|
def set_version(version)
|
|
78
|
+
service = VersionCake::VersionContextService.new(VersionCake.config)
|
|
79
|
+
request.env['versioncake.context'] = service.create_context_from_context(version_context, version)
|
|
64
80
|
@request_version = version
|
|
81
|
+
|
|
82
|
+
check_version!
|
|
65
83
|
end
|
|
66
84
|
end
|
|
67
85
|
end
|
|
@@ -9,7 +9,7 @@ module VersionCake
|
|
|
9
9
|
version
|
|
10
10
|
elsif version.is_a?(String) && /[0-9]+/.match(version)
|
|
11
11
|
version.to_i
|
|
12
|
-
elsif
|
|
12
|
+
elsif version_blank?(version)
|
|
13
13
|
nil
|
|
14
14
|
else
|
|
15
15
|
raise Exception, "Invalid format for version number."
|
|
@@ -20,6 +20,10 @@ module VersionCake
|
|
|
20
20
|
VersionCake.config.version_key
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
def version_blank?(version)
|
|
24
|
+
version.nil? || (version.is_a?(String) && version.length == 0)
|
|
25
|
+
end
|
|
26
|
+
|
|
23
27
|
# Execute should return a number or a numeric string if it successfully finds a version.
|
|
24
28
|
# If no version is found, nil should be returned. Any other results returned will raise
|
|
25
29
|
# an exception.
|
|
@@ -2,8 +2,8 @@ module VersionCake
|
|
|
2
2
|
module TestHelpers
|
|
3
3
|
# Test helper the mimics the middleware because we do not
|
|
4
4
|
# have middleware during tests.
|
|
5
|
-
def set_request_version(resource, version)
|
|
6
|
-
service = VersionCake::VersionContextService.new(
|
|
5
|
+
def set_request_version(resource, version, config=VersionCake.config)
|
|
6
|
+
service = VersionCake::VersionContextService.new(config)
|
|
7
7
|
@request.env['versioncake.context'] = service.create_context resource, version
|
|
8
8
|
end
|
|
9
9
|
|
|
@@ -11,4 +11,4 @@ module VersionCake
|
|
|
11
11
|
@request.env['versioncake.context'] = VersionCake::VersionContext.new(version, resource, status)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
|
-
end
|
|
14
|
+
end
|
data/lib/versioncake/version.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module VersionCake
|
|
2
2
|
class VersionContext
|
|
3
|
-
attr_reader :
|
|
3
|
+
attr_reader :resource, :result
|
|
4
|
+
attr_accessor :version
|
|
4
5
|
|
|
5
6
|
def initialize(version, resource, result)
|
|
6
7
|
@version, @resource, @result = version, resource, result
|
|
@@ -13,8 +14,8 @@ module VersionCake
|
|
|
13
14
|
|
|
14
15
|
# Ordered versions that are equal to or lower
|
|
15
16
|
# than the requested version.
|
|
16
|
-
def
|
|
17
|
-
@resource.
|
|
17
|
+
def available_versions
|
|
18
|
+
@resource.available_versions.reverse.reject { |v| v > @version }
|
|
18
19
|
end
|
|
19
20
|
end
|
|
20
21
|
end
|
|
@@ -3,7 +3,7 @@ module VersionCake
|
|
|
3
3
|
|
|
4
4
|
def initialize(config)
|
|
5
5
|
@versioned_resources = config.versioned_resources
|
|
6
|
-
@default_version = config.
|
|
6
|
+
@default_version = config.default_version
|
|
7
7
|
@strategies = config.extraction_strategies
|
|
8
8
|
end
|
|
9
9
|
|
|
@@ -18,7 +18,7 @@ module VersionCake
|
|
|
18
18
|
request.execute
|
|
19
19
|
|
|
20
20
|
result = if request.failed
|
|
21
|
-
:
|
|
21
|
+
:version_invalid
|
|
22
22
|
else
|
|
23
23
|
check_version(resource, request.version)
|
|
24
24
|
end
|
|
@@ -34,6 +34,12 @@ module VersionCake
|
|
|
34
34
|
VersionCake::VersionContext.new(version, resource, result)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def create_context_from_context(context, version)
|
|
38
|
+
result = check_version(context.resource, version)
|
|
39
|
+
|
|
40
|
+
VersionCake::VersionContext.new(version, context.resource, result)
|
|
41
|
+
end
|
|
42
|
+
|
|
37
43
|
private
|
|
38
44
|
|
|
39
45
|
def check_version(resource, version)
|
|
@@ -7,8 +7,12 @@ module VersionCake
|
|
|
7
7
|
uri, supported_versions, deprecated_versions, obsolete_versions
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
def available_versions
|
|
11
|
+
(@supported_versions.to_a + @deprecated_versions.to_a).sort
|
|
12
|
+
end
|
|
13
|
+
|
|
10
14
|
def latest_version
|
|
11
|
-
|
|
15
|
+
available_versions.last
|
|
12
16
|
end
|
|
13
17
|
end
|
|
14
18
|
end
|
|
@@ -6,7 +6,8 @@ describe RendersController, type: :controller do
|
|
|
6
6
|
|
|
7
7
|
context '#index' do
|
|
8
8
|
render_views
|
|
9
|
-
|
|
9
|
+
let(:config) { VersionCake.config }
|
|
10
|
+
before { set_request_version 'renders', request_version, config }
|
|
10
11
|
before { response_body }
|
|
11
12
|
|
|
12
13
|
context 'when requesting the non latest version' do
|
|
@@ -36,12 +37,34 @@ describe RendersController, type: :controller do
|
|
|
36
37
|
it { expect(response_body).to eq 'template v2' }
|
|
37
38
|
end
|
|
38
39
|
|
|
40
|
+
context 'when requesting without a version' do
|
|
41
|
+
context 'and missing version is configured to unversioned_template' do
|
|
42
|
+
let(:request_version) { nil }
|
|
43
|
+
|
|
44
|
+
# TODO: Restructure
|
|
45
|
+
# Need a better way to stub/unstub the `VersionCake.config` that generates
|
|
46
|
+
# the context and is used in the controller.
|
|
47
|
+
let(:config) do
|
|
48
|
+
VersionCake.config.tap do |config|
|
|
49
|
+
config.missing_version = :unversioned_template
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
after { VersionCake.config.missing_version = nil }
|
|
53
|
+
# /TODO
|
|
54
|
+
|
|
55
|
+
it { expect(controller.request_version).to eq nil }
|
|
56
|
+
it { expect(controller.is_latest_version?).to be_falsey }
|
|
57
|
+
it { expect(controller.is_deprecated_version?).to be_falsey }
|
|
58
|
+
it { expect(response_body).to eq 'base template' }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
39
62
|
context '#set_version' do
|
|
40
|
-
let(:request_options) { { 'override_version' =>
|
|
63
|
+
let(:request_options) { { 'override_version' => 1 } }
|
|
41
64
|
let(:request_version) { 3 }
|
|
42
65
|
|
|
43
|
-
it { expect(controller.request_version).to eq
|
|
44
|
-
it { expect(response_body).to eq 'template
|
|
66
|
+
it { expect(controller.request_version).to eq 1 }
|
|
67
|
+
it { expect(response_body).to eq 'template v1' }
|
|
45
68
|
end
|
|
46
69
|
end
|
|
47
70
|
|
|
@@ -3,25 +3,27 @@ require 'yaml'
|
|
|
3
3
|
|
|
4
4
|
describe VersionCake::Rack::Middleware do
|
|
5
5
|
let(:app) do
|
|
6
|
+
_config = config
|
|
6
7
|
rack = Rack::Builder.new do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
use VersionCake::Rack::Middleware, config
|
|
10
|
-
run lambda { |env| [ 200, {},[ env['versioncake.context'].version ] ] }
|
|
8
|
+
use VersionCake::Rack::Middleware, _config
|
|
9
|
+
run lambda { |env| [ 200, {},[ "version is #{env['versioncake.context'].version}" ] ] }
|
|
11
10
|
end
|
|
12
11
|
Rack::MockRequest.new(rack)
|
|
13
12
|
end
|
|
13
|
+
let(:config) do
|
|
14
|
+
config = VersionCake::Configuration.new
|
|
15
|
+
config.resources { |r| r.resource %r{.*}, [], [], (1..5) }
|
|
16
|
+
config
|
|
17
|
+
end
|
|
14
18
|
|
|
15
19
|
test_cases = YAML.load(File.open('./spec/fixtures/test_cases.yml'))
|
|
16
20
|
test_cases.each do |test_case|
|
|
17
21
|
context 'for a test case' do
|
|
18
|
-
|
|
19
|
-
|
|
20
22
|
let(:data) { test_case['request'] || {} }
|
|
21
23
|
let(:method) { (data['method'] || 'get').to_sym }
|
|
22
24
|
let(:headers) { data['headers'] || {} }
|
|
23
25
|
let(:params) { data['params'] || {} }
|
|
24
|
-
let(:test_response) { test_case['response'] }
|
|
26
|
+
let(:test_response) { "version is #{test_case['response']}" }
|
|
25
27
|
|
|
26
28
|
it "test yml test cases" do
|
|
27
29
|
begin
|
|
@@ -40,4 +42,20 @@ describe VersionCake::Rack::Middleware do
|
|
|
40
42
|
data << "params:#{params}" if params
|
|
41
43
|
"Expected #{data.join(',')} with method #{method} to yield '#{expected_response}', but got '#{actual_response}'"
|
|
42
44
|
end
|
|
45
|
+
|
|
46
|
+
context 'when configured with unversioned template' do
|
|
47
|
+
let(:config) do
|
|
48
|
+
config = VersionCake::Configuration.new
|
|
49
|
+
config.resources { |r| r.resource %r{.*}, [], [], (1..5) }
|
|
50
|
+
config.missing_version = :unversioned_template
|
|
51
|
+
config
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context 'and the request does not contain a version' do
|
|
55
|
+
it 'does not include a version (rails will convert nil => unversioned template)' do
|
|
56
|
+
_response_status, _response_headers, response = app.request('get', '/renders')
|
|
57
|
+
expect(response.body).to eq 'version is ' # nil
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
43
61
|
end
|
|
@@ -60,6 +60,22 @@ describe VersionCake::Configuration do
|
|
|
60
60
|
it { expect(config.latest_version).to eq 54 }
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
+
context '#missing_version' do
|
|
64
|
+
before { config.missing_version = 5 }
|
|
65
|
+
|
|
66
|
+
it { expect(config.missing_version).to eq 5 }
|
|
67
|
+
it { expect(config.default_version).to eq 5 }
|
|
68
|
+
it { expect(config.missing_version_use_unversioned_template).to eq false }
|
|
69
|
+
|
|
70
|
+
context 'when set to use the base template' do
|
|
71
|
+
before { config.missing_version = :unversioned_template }
|
|
72
|
+
|
|
73
|
+
it { expect(config.missing_version).to eq :unversioned_template }
|
|
74
|
+
it { expect(config.default_version).to be_nil }
|
|
75
|
+
it { expect(config.missing_version_use_unversioned_template).to eq true }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
63
79
|
context 'by default' do
|
|
64
80
|
it 'has all extraction strategies' do
|
|
65
81
|
expect(config.extraction_strategies.map(&:class)).to match_array(
|
|
@@ -21,12 +21,13 @@ describe VersionCake::VersionContextService do
|
|
|
21
21
|
let(:config) do
|
|
22
22
|
double('config',
|
|
23
23
|
versioned_resources: [resource_user, resource_all],
|
|
24
|
-
|
|
24
|
+
default_version: default_version,
|
|
25
25
|
extraction_strategies: [
|
|
26
26
|
VersionCake::CustomStrategy.new(lambda{ |req| req.version })
|
|
27
27
|
]
|
|
28
28
|
)
|
|
29
29
|
end
|
|
30
|
+
let(:default_version) { 6 }
|
|
30
31
|
let(:service) { described_class.new(config) }
|
|
31
32
|
|
|
32
33
|
describe '#create_context_from_request' do
|
|
@@ -52,6 +53,38 @@ describe VersionCake::VersionContextService do
|
|
|
52
53
|
it { expect(context.resource).to eq resource_user }
|
|
53
54
|
it { expect(context.result).to eq :obsolete }
|
|
54
55
|
end
|
|
56
|
+
|
|
57
|
+
context 'for a missing version' do
|
|
58
|
+
let(:request) { double(version: nil, path: 'users/123') }
|
|
59
|
+
|
|
60
|
+
it { expect(context.version).to eq 6 }
|
|
61
|
+
it { expect(context.resource).to eq resource_user }
|
|
62
|
+
it { expect(context.result).to eq :supported }
|
|
63
|
+
|
|
64
|
+
context 'when no default version is configured' do
|
|
65
|
+
let(:default_version) { nil }
|
|
66
|
+
|
|
67
|
+
it { expect(context.version).to eq nil }
|
|
68
|
+
it { expect(context.resource).to eq resource_user }
|
|
69
|
+
it { expect(context.result).to eq :no_version }
|
|
70
|
+
|
|
71
|
+
context 'when the version is blank' do
|
|
72
|
+
let(:request) { double(version: '', path: 'users/123') }
|
|
73
|
+
|
|
74
|
+
it { expect(context.version).to eq nil }
|
|
75
|
+
it { expect(context.resource).to eq resource_user }
|
|
76
|
+
it { expect(context.result).to eq :no_version }
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context 'for an invalid version' do
|
|
82
|
+
let(:request) { double(version: 'asdasd', path: 'users/123') }
|
|
83
|
+
|
|
84
|
+
it { expect(context.version).to eq nil }
|
|
85
|
+
it { expect(context.resource).to eq resource_user }
|
|
86
|
+
it { expect(context.result).to eq :version_invalid }
|
|
87
|
+
end
|
|
55
88
|
end
|
|
56
89
|
|
|
57
90
|
describe '#create_context' do
|
|
@@ -81,4 +114,34 @@ describe VersionCake::VersionContextService do
|
|
|
81
114
|
it { expect(context.result).to eq :obsolete }
|
|
82
115
|
end
|
|
83
116
|
end
|
|
117
|
+
|
|
118
|
+
describe '#create_context_from_context' do
|
|
119
|
+
let(:uri) { 'users/21' }
|
|
120
|
+
let(:existing_version) { 1 }
|
|
121
|
+
let(:existing_context) { service.create_context(uri, existing_version) }
|
|
122
|
+
let(:version) { 5 }
|
|
123
|
+
subject(:context) { service.create_context_from_context(existing_context, version) }
|
|
124
|
+
|
|
125
|
+
it { expect(context.version).to eq 5 }
|
|
126
|
+
it { expect(context.resource).to eq resource_user }
|
|
127
|
+
it { expect(context.result).to eq :supported }
|
|
128
|
+
|
|
129
|
+
context 'for a deprecated version' do
|
|
130
|
+
let(:uri) { 'posts/21' }
|
|
131
|
+
let(:version) { 5 }
|
|
132
|
+
|
|
133
|
+
it { expect(context.version).to eq 5 }
|
|
134
|
+
it { expect(context.resource).to eq resource_all }
|
|
135
|
+
it { expect(context.result).to eq :deprecated }
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
context 'for an obsolete version' do
|
|
139
|
+
let(:uri) { 'posts/21' }
|
|
140
|
+
let(:version) { 2 }
|
|
141
|
+
|
|
142
|
+
it { expect(context.version).to eq 2 }
|
|
143
|
+
it { expect(context.resource).to eq resource_all }
|
|
144
|
+
it { expect(context.result).to eq :obsolete }
|
|
145
|
+
end
|
|
146
|
+
end
|
|
84
147
|
end
|
|
@@ -6,29 +6,30 @@ describe VersionCake::VersionContext do
|
|
|
6
6
|
latest_version: 8,
|
|
7
7
|
supported_versions: [5,6,7,8],
|
|
8
8
|
deprecated_versions: [4],
|
|
9
|
+
available_versions: [4,5,6,7,8],
|
|
9
10
|
obsolete_versions: [2,3]
|
|
10
11
|
)
|
|
11
12
|
end
|
|
12
13
|
let(:result) { :supported }
|
|
13
14
|
subject(:context) { described_class.new(version, resource, result) }
|
|
14
15
|
|
|
15
|
-
describe '#
|
|
16
|
+
describe '#available_versions' do
|
|
16
17
|
let(:version) { 7 }
|
|
17
18
|
|
|
18
|
-
it { expect(context.
|
|
19
|
+
it { expect(context.available_versions).to eq [7,6,5,4] }
|
|
19
20
|
|
|
20
21
|
context 'for a deprecated version' do
|
|
21
22
|
let(:version) { 4 }
|
|
22
23
|
let(:result) { :deprecated }
|
|
23
24
|
|
|
24
|
-
it { expect(context.
|
|
25
|
+
it { expect(context.available_versions).to eq [4] }
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
context 'for an obsolete version' do
|
|
28
29
|
let(:version) { 2 }
|
|
29
30
|
let(:result) { :obsolete }
|
|
30
31
|
|
|
31
|
-
it { expect(context.
|
|
32
|
+
it { expect(context.available_versions).to eq [] }
|
|
32
33
|
end
|
|
33
34
|
end
|
|
34
35
|
|
|
@@ -4,6 +4,20 @@ describe VersionCake::VersionedResource do
|
|
|
4
4
|
|
|
5
5
|
let(:resource) { described_class.new('hello/123', [1,2], [3], [4,5,6])}
|
|
6
6
|
|
|
7
|
+
describe '#available_versions' do
|
|
8
|
+
subject { resource.available_versions }
|
|
9
|
+
|
|
10
|
+
it { is_expected.to match_array (3..6).to_a }
|
|
11
|
+
|
|
12
|
+
context 'when given out of order' do
|
|
13
|
+
let(:resource) { described_class.new('hello/123', [1,2], [3], [7,6,4,5])}
|
|
14
|
+
|
|
15
|
+
it 'order them' do
|
|
16
|
+
is_expected.to match_array (3..7).to_a
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
7
21
|
describe '#latest_version' do
|
|
8
22
|
subject { resource.latest_version }
|
|
9
23
|
|
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.2.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:
|
|
12
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: actionpack
|