versioncake 2.5.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Appraisals +12 -0
- data/CHANGELOG.md +18 -1
- data/CONTRIBUTING.md +2 -2
- data/Gemfile.lock +96 -44
- data/README.md +79 -29
- data/RELEASE.md +1 -1
- data/Rakefile +3 -7
- data/gemfiles/rails3.2.gemfile +2 -1
- data/gemfiles/rails3.2.gemfile.lock +34 -10
- data/gemfiles/rails4.0.gemfile +2 -1
- data/gemfiles/rails4.0.gemfile.lock +31 -7
- data/gemfiles/rails4.1.gemfile +1 -1
- data/gemfiles/rails4.1.gemfile.lock +28 -8
- data/gemfiles/rails4.2.gemfile +9 -0
- data/gemfiles/rails4.2.gemfile.lock +133 -0
- data/lib/generators/templates/versioncake.rb +40 -0
- data/lib/generators/versioncake/install_generator.rb +12 -0
- data/lib/versioncake.rb +24 -3
- data/lib/versioncake/configuration.rb +19 -2
- data/lib/versioncake/controller_additions.rb +35 -23
- data/lib/versioncake/engine.rb +7 -0
- data/lib/versioncake/exceptions.rb +4 -0
- data/lib/versioncake/rack/middleware.rb +20 -0
- data/lib/versioncake/strategies/extraction_strategy.rb +8 -3
- data/lib/versioncake/strategies/http_accept_parameter_strategy.rb +2 -2
- data/lib/versioncake/strategies/http_header_strategy.rb +2 -2
- data/lib/versioncake/strategies/path_parameter_strategy.rb +6 -2
- data/lib/versioncake/strategies/query_parameter_strategy.rb +2 -2
- data/lib/versioncake/strategies/request_parameter_strategy.rb +2 -2
- data/lib/versioncake/test_helpers.rb +14 -0
- data/lib/versioncake/version.rb +1 -1
- data/lib/versioncake/version_checker.rb +28 -0
- data/lib/versioncake/version_context.rb +20 -0
- data/lib/versioncake/version_context_service.rb +47 -0
- data/lib/versioncake/versioned_request.rb +22 -33
- data/lib/versioncake/versioned_resource.rb +14 -0
- data/lib/versioncake/view_additions.rb +7 -7
- data/{test → spec}/fixtures/partials/_versioned.erb +0 -0
- data/{test → spec}/fixtures/partials/_versioned.v1.erb +0 -0
- data/{test → spec}/fixtures/partials/_versioned.v2.erb +0 -0
- data/{test → spec}/fixtures/partials/_versioned.v3.erb +0 -0
- data/{test → spec}/fixtures/partials/another_versioned_partial.erb +0 -0
- data/{test → spec}/fixtures/partials/another_versioned_partial.v1.erb +0 -0
- data/{test → spec}/fixtures/templates/unversioned.html.erb +0 -0
- data/{test → spec}/fixtures/templates/v1_extension_scheme.v3.html.erb +0 -0
- data/{test → spec}/fixtures/templates/v1_extension_scheme.v6.json +0 -0
- data/{test → spec}/fixtures/templates/versioned.html.erb +0 -0
- data/{test → spec}/fixtures/templates/versioned.html.v1.erb +0 -0
- data/{test → spec}/fixtures/templates/versioned.html.v2.erb +0 -0
- data/{test → spec}/fixtures/templates/versioned.html.v3.erb +0 -0
- data/spec/fixtures/test_cases.yml +45 -0
- data/spec/integration/controller/renders_controller_spec.rb +73 -0
- data/spec/integration/controller/unversioned_controller_spec.rb +12 -0
- data/spec/integration/rack/middleware_regression_spec.rb +41 -0
- data/spec/integration/view/render_spec.rb +33 -0
- data/spec/integration/view/view_additions_spec.rb +51 -0
- data/spec/rails_helper.rb +41 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/test_app/Rakefile +7 -0
- data/{test → spec/test_app}/app/controllers/renders_controller.rb +0 -0
- data/spec/test_app/app/controllers/unversioned_controller.rb +6 -0
- data/spec/test_app/app/views/renders/index.html.erb +1 -0
- data/{test → spec/test_app}/app/views/renders/index.html.v1.erb +0 -0
- data/{test → spec/test_app}/app/views/renders/index.html.v2.erb +0 -0
- data/spec/test_app/app/views/unversioned/index.html.erb +1 -0
- data/spec/test_app/config.ru +4 -0
- data/{test → spec/test_app}/config/application.rb +4 -6
- data/spec/test_app/config/boot.rb +5 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/initializers/versioncake.rb +45 -0
- data/spec/test_app/config/routes.rb +4 -0
- data/spec/test_app/script/rails +4 -0
- data/spec/unit/cli_spec.rb +36 -0
- data/spec/unit/configuration_spec.rb +61 -0
- data/spec/unit/strategies/extraction_strategy_spec.rb +71 -0
- data/spec/unit/strategies/http_accept_parameter_strategy_spec.rb +20 -0
- data/spec/unit/strategies/http_header_strategy_spec.rb +19 -0
- data/spec/unit/strategies/path_parameter_strategy_spec.rb +18 -0
- data/spec/unit/strategies/query_parameter_strategy_spec.rb +24 -0
- data/spec/unit/strategies/request_parameter_strategy_spec.rb +19 -0
- data/spec/unit/version_checker_spec.rb +60 -0
- data/spec/unit/version_context_service_spec.rb +84 -0
- data/spec/unit/version_context_spec.rb +46 -0
- data/spec/unit/versioned_request_spec.rb +35 -0
- data/spec/unit/versioned_resource_spec.rb +12 -0
- data/versioncake.gemspec +5 -2
- metadata +91 -70
- data/lib/versioncake/railtie.rb +0 -7
- data/test/app/views/renders/index.html.erb +0 -1
- data/test/config.ru +0 -0
- data/test/config/routes.rb +0 -3
- data/test/fixtures/test_cases.yml +0 -70
- data/test/functional/custom_strategy_controller_test.rb +0 -16
- data/test/functional/multiple_strategy_controller_test.rb +0 -24
- data/test/functional/renders_controller_test.rb +0 -71
- data/test/functional/strategy_controller_test.rb +0 -38
- data/test/script/rails +0 -0
- data/test/template/render_test.rb +0 -34
- data/test/test_helper.rb +0 -21
- data/test/unit/cli_test.rb +0 -48
- data/test/unit/configuration_test.rb +0 -45
- data/test/unit/strategies/extraction_strategy_test.rb +0 -70
- data/test/unit/strategies/http_accept_parameter_strategy_test.rb +0 -17
- data/test/unit/strategies/http_header_strategy_test.rb +0 -17
- data/test/unit/strategies/path_parameter_strategy_test.rb +0 -17
- data/test/unit/strategies/query_parameter_strategy_test.rb +0 -22
- data/test/unit/strategies/request_parameter_strategy_test.rb +0 -17
- data/test/unit/versioned_request_test.rb +0 -44
- data/test/unit/view_additions_test.rb +0 -35
@@ -1,17 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
|
3
|
-
class HttpAcceptParameterStrategyTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@strategy = VersionCake::HttpAcceptParameterStrategy.new
|
6
|
-
end
|
7
|
-
|
8
|
-
test "a request with an HTTP_ACCEPT version retrieves the version" do
|
9
|
-
request = stub(:headers => {'HTTP_ACCEPT' => 'application/xml; api_version=11'})
|
10
|
-
assert_equal 11, @strategy.extract(request)
|
11
|
-
end
|
12
|
-
|
13
|
-
test "a request without an HTTP_ACCEPT version returns nil" do
|
14
|
-
request = stub(:headers => {'HTTP_ACCEPT' => 'text/x-dvi; q=.8; mxb=100000; mxt=5.0, text/x-c'})
|
15
|
-
assert_nil @strategy.extract(request)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
|
3
|
-
class HttpHeaderStrategyTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@strategy = VersionCake::HttpHeaderStrategy.new
|
6
|
-
end
|
7
|
-
|
8
|
-
test "a request with an HTTP_X_API_VERSION retrieves the version" do
|
9
|
-
request = stub(:headers => {'HTTP_X_API_VERSION' => '11'})
|
10
|
-
assert_equal 11, @strategy.extract(request)
|
11
|
-
end
|
12
|
-
|
13
|
-
test "a request without an HTTP_X_API_VERSION returns nil" do
|
14
|
-
request = stub(:headers => {'HTTP_ACCEPT' => 'text/x-dvi; q=.8; mxb=100000; mxt=5.0, text/x-c'})
|
15
|
-
assert_nil @strategy.extract(request)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
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
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
|
3
|
-
class QueryParameterStrategyTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@strategy = VersionCake::QueryParameterStrategy.new
|
6
|
-
end
|
7
|
-
|
8
|
-
test "a request with an api_version parameter retrieves the version" do
|
9
|
-
request = stub(:query_parameters => {:api_version => '11', :other => 'parameter'})
|
10
|
-
assert_equal 11, @strategy.extract(request)
|
11
|
-
end
|
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
|
-
|
18
|
-
test "a request without an api_version parameter returns nil" do
|
19
|
-
request = stub(:query_parameters => {:other => 'parameter', :another => 'parameter'})
|
20
|
-
assert_nil @strategy.extract(request)
|
21
|
-
end
|
22
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
|
3
|
-
class RequestParameterStrategyTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@strategy = VersionCake::RequestParameterStrategy.new
|
6
|
-
end
|
7
|
-
|
8
|
-
test "a request with an api_version request parameter retrieves the version" do
|
9
|
-
request = stub(:request_parameters => {:api_version => '11', :other => 'parameter'})
|
10
|
-
assert_equal 11, @strategy.extract(request)
|
11
|
-
end
|
12
|
-
|
13
|
-
test "a request without an api_version request parameter returns nil" do
|
14
|
-
request = stub(:request_parameters => {:other => 'parameter', :another => 'parameter'})
|
15
|
-
assert_nil @strategy.extract(request)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require './test/test_helper'
|
2
|
-
|
3
|
-
class VersionedRequestTest < ActiveSupport::TestCase
|
4
|
-
test "a request with a supported version returns the version" do
|
5
|
-
VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => 2)
|
6
|
-
versioned_request = VersionCake::VersionedRequest.new(stub())
|
7
|
-
assert_equal 2, versioned_request.version
|
8
|
-
end
|
9
|
-
|
10
|
-
test "a request without a version returns the latest version" do
|
11
|
-
VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => nil)
|
12
|
-
versioned_request = VersionCake::VersionedRequest.new(stub())
|
13
|
-
assert_equal 3, versioned_request.version
|
14
|
-
end
|
15
|
-
|
16
|
-
test "a request for a version that is higher than the latest version raises an error" do
|
17
|
-
VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => 99)
|
18
|
-
assert !VersionCake::VersionedRequest.new(stub()).is_version_supported?
|
19
|
-
end
|
20
|
-
|
21
|
-
test "a request for a deprecated version raises an exception" do
|
22
|
-
VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => 2)
|
23
|
-
VersionCake::Configuration.any_instance.stubs(:supports_version? => false)
|
24
|
-
assert !VersionCake::VersionedRequest.new(stub()).is_version_supported?
|
25
|
-
end
|
26
|
-
|
27
|
-
test "has a method to determine if requesting the latest version" do
|
28
|
-
VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => nil)
|
29
|
-
versioned_request = VersionCake::VersionedRequest.new(stub())
|
30
|
-
assert versioned_request.is_latest_version?
|
31
|
-
end
|
32
|
-
|
33
|
-
test "has a method to retrieve the extracted version" do
|
34
|
-
VersionCake::VersionedRequest.any_instance.stubs(:apply_strategies => nil)
|
35
|
-
versioned_request = VersionCake::VersionedRequest.new(stub())
|
36
|
-
assert_nil versioned_request.extracted_version
|
37
|
-
assert_equal 3, versioned_request.version
|
38
|
-
end
|
39
|
-
|
40
|
-
test "the version can be overriden by a parameter" do
|
41
|
-
versioned_request = VersionCake::VersionedRequest.new(stub(), 8)
|
42
|
-
assert_equal 8, versioned_request.version
|
43
|
-
end
|
44
|
-
end
|
@@ -1,35 +0,0 @@
|
|
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
|