-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37
- Loading branch information
Showing
70 changed files
with
766 additions
and
581 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format=progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
spec/integration/controller/custom_strategy_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
|
||
describe RendersController, type: :controller do | ||
render_views | ||
|
||
before do | ||
allow_any_instance_of(VersionCake::Configuration).to \ | ||
receive(:extraction_strategy).and_return(lambda { |_| 2 }) | ||
end | ||
|
||
subject(:render_response) { get :index } | ||
|
||
it { expect(render_response.body).to eq 'template v2' } | ||
end |
30 changes: 30 additions & 0 deletions
30
spec/integration/controller/multiple_strategy_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
|
||
describe RendersController, type: :controller do | ||
render_views | ||
let(:request_options) { {} } | ||
subject(:response) { get :index, request_options } | ||
|
||
context 'with a version in the accept header' do | ||
before { allow(request).to receive(:headers).and_return({'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=1'}) } | ||
|
||
it { expect(response.body).to eq 'template v1' } | ||
end | ||
|
||
context 'when query parameter sets the version' do | ||
let(:request_options) { { 'api_version' => '1' } } | ||
|
||
it 'renders the query parameter when accept parameter isn\'t available' do | ||
expect(response.body).to eq 'template v1' | ||
end | ||
|
||
context 'and the accept header sets the version' do | ||
before { allow(request).to receive(:headers).and_return({'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=2'}) } | ||
|
||
it 'renders the higher priority accept parameter version' do | ||
expect(response.body).to eq 'template v2' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
require 'yaml' | ||
|
||
describe RendersController, type: :controller do | ||
test_cases = YAML.load(File.open('./spec/fixtures/test_cases.yml')) | ||
test_cases.each do |test_case| | ||
context 'for a test case' do | ||
render_views | ||
before do | ||
allow(@request).to receive(:headers).and_return(headers) | ||
controller.versioned_request = nil # clear out the versioned request so it's not cached | ||
end | ||
|
||
let(:request) { test_case['request'] || {} } | ||
let(:headers) { request['headers'] || {} } | ||
let(:params) { request['params'] || {} } | ||
let(:method) { (request['method'] || 'get').to_sym } | ||
let(:test_response) { test_case['response'] } | ||
|
||
it "test yml test cases" do | ||
begin | ||
send(method, :index, params) | ||
expect(response.body).to(eq(test_response), custom_message(headers, params, method, response.body, test_response)) | ||
rescue => e | ||
raise custom_message(headers, params, method, response.body, test_response) + ", but it failed with an exception '#{e.message}'" | ||
end | ||
end | ||
end | ||
end | ||
|
||
def custom_message(headers, params, method, actual_response, expected_response) | ||
data = [] | ||
data << "headers:#{headers}" if headers | ||
data << "params:#{params}" if params | ||
"Expected #{data.join(',')} with method #{method} to yield '#{expected_response}', but got '#{actual_response}'" | ||
end | ||
end |
Oops, something went wrong.