versioncake 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/Appraisals +6 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +4 -4
- data/README.md +65 -30
- data/RELEASE.md +1 -1
- data/bin/versioncake +9 -0
- data/gemfiles/rails3.2.gemfile.lock +6 -2
- data/gemfiles/rails4.0.gemfile.lock +1 -1
- data/gemfiles/rails4.1.gemfile +9 -0
- data/gemfiles/rails4.1.gemfile.lock +87 -0
- data/lib/versioncake/cli.rb +60 -0
- data/lib/versioncake/configuration.rb +21 -21
- data/lib/versioncake/railtie.rb +3 -19
- data/lib/versioncake/strategies/extraction_strategy.rb +5 -5
- data/lib/versioncake/strategies/http_accept_parameter_strategy.rb +1 -1
- data/lib/versioncake/strategies/http_header_strategy.rb +2 -2
- data/lib/versioncake/strategies/path_parameter_strategy.rb +11 -0
- data/lib/versioncake/strategies/query_parameter_strategy.rb +2 -2
- data/lib/versioncake/strategies/request_parameter_strategy.rb +2 -2
- data/lib/versioncake/version.rb +1 -1
- data/lib/versioncake/versioned_request.rb +10 -6
- data/lib/versioncake/view_additions.rb +67 -10
- data/lib/versioncake.rb +2 -0
- data/test/{fixtures/templates/versioned.v1.html.erb → app/views/renders/index.html.v1.erb} +0 -0
- data/test/{fixtures/templates/versioned.v2.html.erb → app/views/renders/index.html.v2.erb} +0 -0
- data/test/config/application.rb +3 -2
- data/test/fixtures/templates/v1_extension_scheme.v3.html.erb +7 -0
- data/test/fixtures/templates/v1_extension_scheme.v6.json +4 -0
- data/test/fixtures/templates/versioned.html.v1.erb +1 -0
- data/test/fixtures/templates/versioned.html.v2.erb +1 -0
- data/test/fixtures/templates/{versioned.v3.html.erb → versioned.html.v3.erb} +0 -0
- data/test/fixtures/test_cases.yml +70 -0
- data/test/functional/custom_strategy_controller_test.rb +16 -0
- data/test/functional/multiple_strategy_controller_test.rb +24 -0
- data/test/functional/renders_controller_test.rb +14 -168
- data/test/functional/strategy_controller_test.rb +37 -0
- data/test/unit/cli_test.rb +48 -0
- data/test/unit/configuration_test.rb +15 -19
- data/test/unit/strategies/extraction_strategy_test.rb +2 -2
- data/test/unit/strategies/path_parameter_strategy_test.rb +17 -0
- data/test/unit/strategies/query_parameter_strategy_test.rb +5 -0
- data/test/unit/versioned_request_test.rb +1 -1
- data/test/unit/view_additions_test.rb +35 -0
- data/versioncake.gemspec +1 -0
- metadata +25 -9
- data/test/app/views/renders/index.v1.html.erb +0 -1
- data/test/app/views/renders/index.v2.html.erb +0 -1
@@ -2,48 +2,44 @@ require './test/test_helper'
|
|
2
2
|
|
3
3
|
class ConfigurationTest < ActiveSupport::TestCase
|
4
4
|
setup do
|
5
|
-
@
|
6
|
-
end
|
7
|
-
|
8
|
-
teardown do
|
9
|
-
VersionCake::Configuration.supported_version_numbers = @previous_versions
|
5
|
+
@config = VersionCake::Configuration.new
|
10
6
|
end
|
11
7
|
|
12
8
|
test "supported_version_numbers can be set with range" do
|
13
|
-
|
14
|
-
assert_equal [7,6,5,4,3,2,1],
|
9
|
+
@config.supported_version_numbers = (1..7)
|
10
|
+
assert_equal [7,6,5,4,3,2,1], @config.supported_version_numbers
|
15
11
|
end
|
16
12
|
|
17
13
|
test "supported_version_numbers can be set with an unordered array" do
|
18
|
-
|
19
|
-
assert_equal [7,6,5,4,3,2,1],
|
14
|
+
@config.supported_version_numbers = [2,4,1,5,3,6,7]
|
15
|
+
assert_equal [7,6,5,4,3,2,1], @config.supported_version_numbers
|
20
16
|
end
|
21
17
|
|
22
18
|
test "supported_version_numbers can be set with a single value" do
|
23
|
-
|
24
|
-
assert_equal [19],
|
19
|
+
@config.supported_version_numbers = 19
|
20
|
+
assert_equal [19], @config.supported_version_numbers
|
25
21
|
end
|
26
22
|
|
27
23
|
test "supports_version? is only true for given supported versions" do
|
28
|
-
|
29
|
-
|
30
|
-
assert
|
24
|
+
@config.supported_version_numbers = (1..7)
|
25
|
+
@config.supported_version_numbers.each do |supported_version|
|
26
|
+
assert @config.supports_version? supported_version
|
31
27
|
end
|
32
28
|
end
|
33
29
|
|
34
30
|
test "supports_version? is not true for other versions" do
|
35
|
-
|
31
|
+
@config.supported_version_numbers = (1..7)
|
36
32
|
[-2,-1,0,8,9,10].each do |unsupported_version|
|
37
|
-
assert
|
33
|
+
assert !@config.supports_version?(unsupported_version)
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
41
37
|
test "latest_version retrieves the highest supported version" do
|
42
|
-
|
43
|
-
assert_equal 54,
|
38
|
+
@config.supported_version_numbers = [4,1,3,9,2,54]
|
39
|
+
assert_equal 54, @config.latest_version
|
44
40
|
end
|
45
41
|
|
46
42
|
test "default supported_version_numbers should be a logic set of version numbers" do
|
47
|
-
assert_equal
|
43
|
+
assert_equal (1..10).to_a.reverse, @config.supported_version_numbers
|
48
44
|
end
|
49
45
|
end
|
@@ -7,11 +7,11 @@ class ExtractionStrategyTest < ActiveSupport::TestCase
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
test "extract will convert the
|
10
|
+
test "extract will convert the result to integer" do
|
11
11
|
class TestStrategy < VersionCake::ExtractionStrategy
|
12
12
|
def execute(request); "123"; end
|
13
13
|
end
|
14
|
-
assert_equal TestStrategy.new.extract("request")
|
14
|
+
assert_equal 123, TestStrategy.new.extract("request")
|
15
15
|
end
|
16
16
|
|
17
17
|
test "it can lookup a strategy" do
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
|
3
|
+
class PathParameterStrategyTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@strategy = VersionCake::PathParameterStrategy.new
|
6
|
+
end
|
7
|
+
|
8
|
+
test "a request with an api_version path parameter retrieves the version" do
|
9
|
+
request = stub(:path_parameters => {:api_version => '11', :other => 'parameter'})
|
10
|
+
assert_equal 11, @strategy.extract(request)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "a request without an api_version path parameter returns nil" do
|
14
|
+
request = stub(:path_parameters => {:other => 'parameter', :another => 'parameter'})
|
15
|
+
assert_nil @strategy.extract(request)
|
16
|
+
end
|
17
|
+
end
|
@@ -10,6 +10,11 @@ class QueryParameterStrategyTest < ActiveSupport::TestCase
|
|
10
10
|
assert_equal 11, @strategy.extract(request)
|
11
11
|
end
|
12
12
|
|
13
|
+
test "a request with an Integer api_version parameter retrieves the version" do
|
14
|
+
request = stub(:query_parameters => {:api_version => 11, :other => 'parameter'})
|
15
|
+
assert_equal 11, @strategy.extract(request)
|
16
|
+
end
|
17
|
+
|
13
18
|
test "a request without an api_version parameter returns nil" do
|
14
19
|
request = stub(:query_parameters => {:other => 'parameter', :another => 'parameter'})
|
15
20
|
assert_nil @strategy.extract(request)
|
@@ -22,7 +22,7 @@ class VersionedRequestTest < ActiveSupport::TestCase
|
|
22
22
|
|
23
23
|
test "a request for a deprecated version raises an exception" do
|
24
24
|
VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => 2)
|
25
|
-
VersionCake::Configuration.stubs(:supports_version? => false)
|
25
|
+
VersionCake::Configuration.any_instance.stubs(:supports_version? => false)
|
26
26
|
assert_raise ActionController::RoutingError do
|
27
27
|
VersionCake::VersionedRequest.new(stub())
|
28
28
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
|
3
|
+
class ViewAdditionsTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
@resolver = ActionView::PathResolver.new
|
6
|
+
end
|
7
|
+
|
8
|
+
test "it retrieves the correct handler and format when only handler and format are present" do
|
9
|
+
handler, format = @resolver.extract_handler_and_format('application.html.erb', nil)
|
10
|
+
assert_equal 'text/html', format.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
test "it retrieves the correct handler and format when only handler, format and version are present" do
|
14
|
+
handler, format = @resolver.extract_handler_and_format('application.json.v1.jbuilder', nil)
|
15
|
+
assert_equal 'application/json', format.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
test "it retrieves the correct handler and format when only handler, format and locale are present" do
|
19
|
+
handler, format = @resolver.extract_handler_and_format('application.en.json.jbuilder', nil)
|
20
|
+
assert_equal 'application/json', format.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
test "it retrieves the correct handler and format when only handler, format, locale and version are present" do
|
24
|
+
handler, format = @resolver.extract_handler_and_format('application.en.json.v1.jbuilder', nil)
|
25
|
+
assert_equal 'application/json', format.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
if ActionPack::VERSION::MAJOR == 4 && ActionPack::VERSION::MINOR >= 1
|
29
|
+
test "it retrieves the correct handler and format when only handler, format, variant and version are present" do
|
30
|
+
handler, format = @resolver.extract_handler_and_format('application.json+tablet.v1.jbuilder', nil)
|
31
|
+
assert_equal 'application/json', format.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/versioncake.gemspec
CHANGED
@@ -5,6 +5,7 @@ require "versioncake/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "versioncake"
|
7
7
|
s.version = VersionCake::VERSION
|
8
|
+
s.license = 'MIT'
|
8
9
|
s.authors = ["Jim Jones", "Ben Willis"]
|
9
10
|
s.email = ["jim.jones1@gmail.com", "benjamin.willis@gmail.com"]
|
10
11
|
s.homepage = "https://github.com/bwillis/versioncake"
|
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:
|
4
|
+
version: 2.0.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: 2014-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -141,7 +141,8 @@ description: Render versioned views automagically based on the clients requested
|
|
141
141
|
email:
|
142
142
|
- jim.jones1@gmail.com
|
143
143
|
- benjamin.willis@gmail.com
|
144
|
-
executables:
|
144
|
+
executables:
|
145
|
+
- versioncake
|
145
146
|
extensions: []
|
146
147
|
extra_rdoc_files: []
|
147
148
|
files:
|
@@ -155,12 +156,16 @@ files:
|
|
155
156
|
- README.md
|
156
157
|
- RELEASE.md
|
157
158
|
- Rakefile
|
159
|
+
- bin/versioncake
|
158
160
|
- gemfiles/rails3.2.gemfile
|
159
161
|
- gemfiles/rails3.2.gemfile.lock
|
160
162
|
- gemfiles/rails4.0.gemfile
|
161
163
|
- gemfiles/rails4.0.gemfile.lock
|
164
|
+
- gemfiles/rails4.1.gemfile
|
165
|
+
- gemfiles/rails4.1.gemfile.lock
|
162
166
|
- images/versioncake-logo450x100.png
|
163
167
|
- lib/versioncake.rb
|
168
|
+
- lib/versioncake/cli.rb
|
164
169
|
- lib/versioncake/configuration.rb
|
165
170
|
- lib/versioncake/controller_additions.rb
|
166
171
|
- lib/versioncake/railtie.rb
|
@@ -168,6 +173,7 @@ files:
|
|
168
173
|
- lib/versioncake/strategies/extraction_strategy.rb
|
169
174
|
- lib/versioncake/strategies/http_accept_parameter_strategy.rb
|
170
175
|
- lib/versioncake/strategies/http_header_strategy.rb
|
176
|
+
- lib/versioncake/strategies/path_parameter_strategy.rb
|
171
177
|
- lib/versioncake/strategies/query_parameter_strategy.rb
|
172
178
|
- lib/versioncake/strategies/request_parameter_strategy.rb
|
173
179
|
- lib/versioncake/version.rb
|
@@ -175,8 +181,8 @@ files:
|
|
175
181
|
- lib/versioncake/view_additions.rb
|
176
182
|
- test/app/controllers/renders_controller.rb
|
177
183
|
- test/app/views/renders/index.html.erb
|
178
|
-
- test/app/views/renders/index.v1.
|
179
|
-
- test/app/views/renders/index.v2.
|
184
|
+
- test/app/views/renders/index.html.v1.erb
|
185
|
+
- test/app/views/renders/index.html.v2.erb
|
180
186
|
- test/config.ru
|
181
187
|
- test/config/application.rb
|
182
188
|
- test/config/routes.rb
|
@@ -187,24 +193,34 @@ files:
|
|
187
193
|
- test/fixtures/partials/another_versioned_partial.erb
|
188
194
|
- test/fixtures/partials/another_versioned_partial.v1.erb
|
189
195
|
- test/fixtures/templates/unversioned.html.erb
|
196
|
+
- test/fixtures/templates/v1_extension_scheme.v3.html.erb
|
197
|
+
- test/fixtures/templates/v1_extension_scheme.v6.json
|
190
198
|
- test/fixtures/templates/versioned.html.erb
|
191
|
-
- test/fixtures/templates/versioned.v1.
|
192
|
-
- test/fixtures/templates/versioned.v2.
|
193
|
-
- test/fixtures/templates/versioned.v3.
|
199
|
+
- test/fixtures/templates/versioned.html.v1.erb
|
200
|
+
- test/fixtures/templates/versioned.html.v2.erb
|
201
|
+
- test/fixtures/templates/versioned.html.v3.erb
|
202
|
+
- test/fixtures/test_cases.yml
|
203
|
+
- test/functional/custom_strategy_controller_test.rb
|
204
|
+
- test/functional/multiple_strategy_controller_test.rb
|
194
205
|
- test/functional/renders_controller_test.rb
|
206
|
+
- test/functional/strategy_controller_test.rb
|
195
207
|
- test/script/rails
|
196
208
|
- test/template/render_test.rb
|
197
209
|
- test/test_helper.rb
|
210
|
+
- test/unit/cli_test.rb
|
198
211
|
- test/unit/configuration_test.rb
|
199
212
|
- test/unit/strategies/extraction_strategy_test.rb
|
200
213
|
- test/unit/strategies/http_accept_parameter_strategy_test.rb
|
201
214
|
- test/unit/strategies/http_header_strategy_test.rb
|
215
|
+
- test/unit/strategies/path_parameter_strategy_test.rb
|
202
216
|
- test/unit/strategies/query_parameter_strategy_test.rb
|
203
217
|
- test/unit/strategies/request_parameter_strategy_test.rb
|
204
218
|
- test/unit/versioned_request_test.rb
|
219
|
+
- test/unit/view_additions_test.rb
|
205
220
|
- versioncake.gemspec
|
206
221
|
homepage: https://github.com/bwillis/versioncake
|
207
|
-
licenses:
|
222
|
+
licenses:
|
223
|
+
- MIT
|
208
224
|
metadata: {}
|
209
225
|
post_install_message:
|
210
226
|
rdoc_options: []
|
@@ -1 +0,0 @@
|
|
1
|
-
index.v1.html.erb
|
@@ -1 +0,0 @@
|
|
1
|
-
index.v2.html.erb
|