versioncake 2.5.0 → 3.0.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 +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
data/test/config/routes.rb
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# http_header_strategy
|
|
2
|
-
- request:
|
|
3
|
-
headers:
|
|
4
|
-
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=1"
|
|
5
|
-
response: "template v1"
|
|
6
|
-
|
|
7
|
-
- request:
|
|
8
|
-
headers:
|
|
9
|
-
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=2"
|
|
10
|
-
response: "template v2"
|
|
11
|
-
|
|
12
|
-
- request:
|
|
13
|
-
headers:
|
|
14
|
-
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=INVALID"
|
|
15
|
-
response: "template v2"
|
|
16
|
-
|
|
17
|
-
# request_parameter_strategy
|
|
18
|
-
- request:
|
|
19
|
-
method: post
|
|
20
|
-
params:
|
|
21
|
-
api_version: "1"
|
|
22
|
-
response: "template v1"
|
|
23
|
-
|
|
24
|
-
- request:
|
|
25
|
-
method: post
|
|
26
|
-
params:
|
|
27
|
-
api_version: "2"
|
|
28
|
-
response: "template v2"
|
|
29
|
-
|
|
30
|
-
- request:
|
|
31
|
-
method: post
|
|
32
|
-
params:
|
|
33
|
-
api_version: "INVALID"
|
|
34
|
-
response: "template v2"
|
|
35
|
-
|
|
36
|
-
# query_parameter_strategy
|
|
37
|
-
- request:
|
|
38
|
-
params:
|
|
39
|
-
api_version: "1"
|
|
40
|
-
response: "template v1"
|
|
41
|
-
|
|
42
|
-
- request:
|
|
43
|
-
params:
|
|
44
|
-
api_version: "2"
|
|
45
|
-
response: "template v2"
|
|
46
|
-
|
|
47
|
-
- request:
|
|
48
|
-
params:
|
|
49
|
-
api_version: "INVALID"
|
|
50
|
-
response: "template v2"
|
|
51
|
-
|
|
52
|
-
# http_header_strategy
|
|
53
|
-
- request:
|
|
54
|
-
headers:
|
|
55
|
-
HTTP_X_API_VERSION: "1"
|
|
56
|
-
response: "template v1"
|
|
57
|
-
|
|
58
|
-
- request:
|
|
59
|
-
headers:
|
|
60
|
-
HTTP_X_API_VERSION: "2"
|
|
61
|
-
response: "template v2"
|
|
62
|
-
|
|
63
|
-
- request:
|
|
64
|
-
headers:
|
|
65
|
-
HTTP_X_API_VERSION: "INVALID"
|
|
66
|
-
response: "template v2"
|
|
67
|
-
|
|
68
|
-
# general
|
|
69
|
-
- request:
|
|
70
|
-
response: "template v2"
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
require './test/test_helper'
|
|
2
|
-
require 'action_controller'
|
|
3
|
-
require 'action_controller/test_case'
|
|
4
|
-
|
|
5
|
-
class CustomStrategyTest < ActionController::TestCase
|
|
6
|
-
tests RendersController
|
|
7
|
-
|
|
8
|
-
setup do
|
|
9
|
-
VersionCake::Configuration.any_instance.stubs(:extraction_strategy => lambda { |request| 2 })
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
test "renders version 2 of the partial based on the header Accept" do
|
|
13
|
-
get :index
|
|
14
|
-
assert_equal "template v2", @response.body
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require './test/test_helper'
|
|
2
|
-
require 'action_controller'
|
|
3
|
-
require 'action_controller/test_case'
|
|
4
|
-
|
|
5
|
-
class MultipleStrategyTest < ActionController::TestCase
|
|
6
|
-
tests RendersController
|
|
7
|
-
|
|
8
|
-
test "renders version 1 of the partial based on the header Accept" do
|
|
9
|
-
@controller.request.stubs(:headers).returns({"HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=1"})
|
|
10
|
-
get :index
|
|
11
|
-
assert_equal "template v1", @response.body
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
test "renders the query parameter when accept parameter isn't available" do
|
|
15
|
-
get :index, "api_version" => "1"
|
|
16
|
-
assert_equal "template v1", @response.body
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
test "renders the higher priority accept parameter version" do
|
|
20
|
-
@controller.request.stubs(:headers).returns({"HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=2"})
|
|
21
|
-
get :index, "api_version" => "1"
|
|
22
|
-
assert_equal "template v2", @response.body
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
require './test/test_helper'
|
|
2
|
-
require 'action_controller'
|
|
3
|
-
require 'action_controller/test_case'
|
|
4
|
-
|
|
5
|
-
class RendersControllerTest < ActionController::TestCase
|
|
6
|
-
|
|
7
|
-
test "render latest version of partial" do
|
|
8
|
-
get :index
|
|
9
|
-
assert_equal "template v2", @response.body
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
test "exposes the requested version" do
|
|
13
|
-
get :index, "api_version" => "1"
|
|
14
|
-
assert_equal 1, @controller.requested_version
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
test "exposes latest version when requesting the latest" do
|
|
18
|
-
get :index, "api_version" => "3"
|
|
19
|
-
assert @controller.is_latest_version
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
test "reports not the latest version" do
|
|
23
|
-
get :index, "api_version" => "1"
|
|
24
|
-
assert !@controller.is_latest_version
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
test "exposes the derived version when the version is not set and no default" do
|
|
28
|
-
get :index
|
|
29
|
-
assert_equal 3, @controller.derived_version
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test "exposes the default version when the version is not set default is set" do
|
|
33
|
-
VersionCake::Configuration.any_instance.stubs(:default_version => 1)
|
|
34
|
-
get :index
|
|
35
|
-
assert_equal 1, @controller.derived_version
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
test "requested version is blank when the version is not set" do
|
|
39
|
-
get :index
|
|
40
|
-
assert @controller.requested_version.blank?
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
test "set_version can be called to override the requested version" do
|
|
44
|
-
get :index, "api_version" => "1", "override_version" => 2
|
|
45
|
-
assert_equal 2, @controller.derived_version
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
test "responds with 404 when the version is larger than the supported version" do
|
|
49
|
-
assert_raise VersionCake::UnsupportedVersionError do
|
|
50
|
-
get :index, "api_version" => "4"
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
test "responds with 404 when the version is lower than the latest version, but not an available version" do
|
|
55
|
-
assert_raise VersionCake::UnsupportedVersionError do
|
|
56
|
-
get :index, "api_version" => "0"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test "render the default version version of the partial" do
|
|
61
|
-
VersionCake::Configuration.any_instance.stubs(:default_version => 1)
|
|
62
|
-
get :index, "api_version" => "abc"
|
|
63
|
-
assert_equal "template v1", @response.body
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
test "derived_version can be called before the before_filter and it returns the request version" do
|
|
67
|
-
@controller.instance_variable_set("@_lookup_context", mock(:versions= => nil))
|
|
68
|
-
@controller.request.stubs(:query_parameters => {:api_version => "2"})
|
|
69
|
-
assert_equal 2, @controller.derived_version
|
|
70
|
-
end
|
|
71
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require './test/test_helper'
|
|
2
|
-
require 'action_controller'
|
|
3
|
-
require 'action_controller/test_case'
|
|
4
|
-
require 'yaml'
|
|
5
|
-
|
|
6
|
-
class StrategyControllerTest < ActionController::TestCase
|
|
7
|
-
tests RendersController
|
|
8
|
-
|
|
9
|
-
setup do
|
|
10
|
-
@test_cases = YAML.load(File.open(Rails.root.join('fixtures', 'test_cases.yml')))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test "test yml test cases" do
|
|
14
|
-
@test_cases.each do |test_case|
|
|
15
|
-
request = (test_case['request'] || {})
|
|
16
|
-
headers = request['headers']
|
|
17
|
-
params = request['params']
|
|
18
|
-
method = (request['method'] || "get").to_sym
|
|
19
|
-
response = test_case['response']
|
|
20
|
-
@controller.request.stubs(:headers).returns(headers || {})
|
|
21
|
-
@controller.versioned_request = nil # clear out the versioned request so it's not cached
|
|
22
|
-
begin
|
|
23
|
-
send(method, :index, params || {})
|
|
24
|
-
assert_equal(response, @response.body, custom_message(headers, params, method, response))
|
|
25
|
-
rescue => e
|
|
26
|
-
fail(custom_message(headers, params, method, response) + ", but it failed with an exception '#{e.message}'")
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def custom_message(headers, params, method, response)
|
|
32
|
-
data = []
|
|
33
|
-
data << "headers:#{headers}" if headers
|
|
34
|
-
data << "params:#{params}" if params
|
|
35
|
-
"Expected #{data.join(",")} with method #{method} to yield #{response}"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
end
|
data/test/script/rails
DELETED
|
File without changes
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
require "./test/test_helper"
|
|
2
|
-
|
|
3
|
-
class VersionRenderTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
|
-
def setup
|
|
6
|
-
path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH)
|
|
7
|
-
view_paths = ActionView::PathSet.new([path])
|
|
8
|
-
@view = ActionView::Base.new(view_paths)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def test_regression_renders_unversioned_template
|
|
12
|
-
@view.lookup_context.versions = [:v0]
|
|
13
|
-
assert_equal "template", @view.render(:template => "templates/versioned")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_render_template_defaults_to_latest_template_version
|
|
17
|
-
assert_equal "template v3", @view.render(:template => "templates/versioned")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_render_template_with_parameter_version_override
|
|
21
|
-
assert_equal "template v1", @view.render(:template => "templates/versioned", :versions => :v1)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_render_template_with_legacy_version
|
|
25
|
-
@view.lookup_context.versions = [:v2]
|
|
26
|
-
assert_equal "template v2", @view.render(:template => "templates/versioned")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_render_template_gracefully_degrades
|
|
30
|
-
@view.lookup_context.versions = [:v4,:v3,:v2,:v1]
|
|
31
|
-
assert_equal "template v3", @view.render(:template => "templates/versioned")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
end
|
data/test/test_helper.rb
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require 'coveralls'
|
|
2
|
-
Coveralls.wear!
|
|
3
|
-
|
|
4
|
-
require 'bundler'
|
|
5
|
-
Bundler.require
|
|
6
|
-
|
|
7
|
-
require 'versioncake'
|
|
8
|
-
|
|
9
|
-
ENV["RAILS_ENV"] = 'test'
|
|
10
|
-
|
|
11
|
-
require 'rails/test_help'
|
|
12
|
-
require 'test/unit'
|
|
13
|
-
|
|
14
|
-
require 'mocha/setup'
|
|
15
|
-
|
|
16
|
-
require File.expand_path('../config/application', __FILE__)
|
|
17
|
-
|
|
18
|
-
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
|
19
|
-
FIXTURES = Pathname.new(FIXTURE_LOAD_PATH)
|
|
20
|
-
|
|
21
|
-
RendersTest::Application.initialize!
|
data/test/unit/cli_test.rb
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
require './test/test_helper'
|
|
2
|
-
require './lib/versioncake/cli'
|
|
3
|
-
|
|
4
|
-
class CliTest < ActiveSupport::TestCase
|
|
5
|
-
|
|
6
|
-
setup do
|
|
7
|
-
File.stubs :rename
|
|
8
|
-
capture_stdout(true)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
teardown do
|
|
12
|
-
capture_stdout(false)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def capture_stdout(flag=true)
|
|
16
|
-
if flag
|
|
17
|
-
out = StringIO.new
|
|
18
|
-
$stdout = out
|
|
19
|
-
else
|
|
20
|
-
$stdout = STDOUT
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
test 'it can detect old file names' do
|
|
25
|
-
renamed_files = VersionCake::Cli.new.migrate('./test/fixtures/templates')
|
|
26
|
-
assert_equal 2, renamed_files.size
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
test 'it renames old filenames to new filenames' do
|
|
30
|
-
renamed_files = VersionCake::Cli.new.migrate('./test/fixtures/templates')
|
|
31
|
-
expected_renamed_files = [
|
|
32
|
-
['./test/fixtures/templates/v1_extension_scheme.v3.html.erb', './test/fixtures/templates/v1_extension_scheme.html.v3.erb'],
|
|
33
|
-
['./test/fixtures/templates/v1_extension_scheme.v6.json', './test/fixtures/templates/v1_extension_scheme.json.v6']
|
|
34
|
-
]
|
|
35
|
-
assert_empty expected_renamed_files - renamed_files
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
test 'it reports no files changed when new filenames exist' do
|
|
39
|
-
assert_empty VersionCake::Cli.new.migrate('./test/app/views')
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
test 'it raises if it cannot find the path' do
|
|
43
|
-
assert_raises ArgumentError do
|
|
44
|
-
VersionCake::Cli.new.migrate('./a/missing/path')
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
require './test/test_helper'
|
|
2
|
-
|
|
3
|
-
class ConfigurationTest < ActiveSupport::TestCase
|
|
4
|
-
setup do
|
|
5
|
-
@config = VersionCake::Configuration.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
test "supported_version_numbers can be set with range" do
|
|
9
|
-
@config.supported_version_numbers = (1..7)
|
|
10
|
-
assert_equal [7,6,5,4,3,2,1], @config.supported_version_numbers
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test "supported_version_numbers can be set with an unordered array" do
|
|
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
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
test "supported_version_numbers can be set with a single value" do
|
|
19
|
-
@config.supported_version_numbers = 19
|
|
20
|
-
assert_equal [19], @config.supported_version_numbers
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test "supports_version? is only true for given supported versions" do
|
|
24
|
-
@config.supported_version_numbers = (1..7)
|
|
25
|
-
@config.supported_version_numbers.each do |supported_version|
|
|
26
|
-
assert @config.supports_version? supported_version
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
test "supports_version? is not true for other versions" do
|
|
31
|
-
@config.supported_version_numbers = (1..7)
|
|
32
|
-
[-2,-1,0,8,9,10].each do |unsupported_version|
|
|
33
|
-
assert !@config.supports_version?(unsupported_version)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
test "latest_version retrieves the highest supported version" do
|
|
38
|
-
@config.supported_version_numbers = [4,1,3,9,2,54]
|
|
39
|
-
assert_equal 54, @config.latest_version
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
test "default supported_version_numbers should be a logic set of version numbers" do
|
|
43
|
-
assert_equal (1..10).to_a.reverse, @config.supported_version_numbers
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
require './test/test_helper'
|
|
2
|
-
|
|
3
|
-
class ExtractionStrategyTest < ActiveSupport::TestCase
|
|
4
|
-
test "execute is required for a strategy" do
|
|
5
|
-
assert_raise(Exception) do
|
|
6
|
-
VersionCake::ExtractionStrategy.new.execute("request")
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
test "custom strategy result will be converted to integer" do
|
|
11
|
-
class TestStrategy < VersionCake::ExtractionStrategy
|
|
12
|
-
def execute(request); "123"; end
|
|
13
|
-
end
|
|
14
|
-
assert_equal 123, TestStrategy.new.extract("request")
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
test "custom strategy result will be returned" do
|
|
18
|
-
class TestStrategy < VersionCake::ExtractionStrategy
|
|
19
|
-
def execute(request); 123; end
|
|
20
|
-
end
|
|
21
|
-
assert_equal 123, TestStrategy.new.extract("request")
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
test "custom strategy will fail if it returns unexpected result" do
|
|
25
|
-
class TestStrategy < VersionCake::ExtractionStrategy
|
|
26
|
-
def execute(request); Object.new; end
|
|
27
|
-
end
|
|
28
|
-
assert_nil TestStrategy.new.extract("request")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
test "it can lookup a strategy" do
|
|
32
|
-
strategy = VersionCake::ExtractionStrategy.lookup(:query_parameter)
|
|
33
|
-
assert_equal VersionCake::QueryParameterStrategy, strategy.class
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
test "it creates a custom strategy for a proc" do
|
|
37
|
-
strategy = VersionCake::ExtractionStrategy.lookup(lambda{|req|})
|
|
38
|
-
assert_equal VersionCake::CustomStrategy, strategy.class
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
test "it wraps a custom object" do
|
|
42
|
-
class FakeStrategy
|
|
43
|
-
def execute(request);end
|
|
44
|
-
end
|
|
45
|
-
strategy = VersionCake::ExtractionStrategy.lookup(FakeStrategy.new)
|
|
46
|
-
assert_equal VersionCake::CustomStrategy, strategy.class
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
test "it calls a custom objects execute method" do
|
|
50
|
-
class FakeStrategy
|
|
51
|
-
def execute(request)
|
|
52
|
-
9999
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
strategy = VersionCake::ExtractionStrategy.lookup(FakeStrategy.new)
|
|
56
|
-
assert_equal 9999, strategy.execute(nil)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
test "it fails to create a custom strategy for a proc with no parameters" do
|
|
60
|
-
assert_raise(Exception) do
|
|
61
|
-
VersionCake::ExtractionStrategy.lookup(lambda{})
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
test "it raises error when no strategy is found" do
|
|
66
|
-
assert_raise(Exception) do
|
|
67
|
-
VersionCake::ExtractionStrategy.lookup(:fake_extraction)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|