Skip to content

Commit

Permalink
Fix multiple version definitions for path versioning (#1414)
Browse files Browse the repository at this point in the history
Closes #1400.
  • Loading branch information
Vasiliy authored and dblock committed Jun 8, 2016
1 parent b9ba3d8 commit 4d1883f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* [#1365](https://github.com/ruby-grape/grape/pull/1365): Fix finding exception handler in error middleware - [@ktimothy](https://github.com/ktimothy).
* [#1380](https://github.com/ruby-grape/grape/pull/1380): Fix `allow_blank: false` for `Time` attributes with valid values causes `NoMethodError` - [@ipkes](https://github.com/ipkes).
* [#1384](https://github.com/ruby-grape/grape/pull/1384): Fix parameter validation with an empty optional nested `Array` - [@ipkes](https://github.com/ipkes).
* [#1414](https://github.com/ruby-grape/grape/pull/1414): Fix multiple version definitions for path versioning - [@304](https://github.com/304).

0.16.2 (4/12/2016)
==================
Expand Down
7 changes: 4 additions & 3 deletions lib/grape/dsl/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ def version(*args, &block)
if args.any?
options = args.extract_options!
options = options.reverse_merge(using: :path)
requested_versions = args.flatten

raise Grape::Exceptions::MissingVendorOption.new if options[:using] == :header && !options.key?(:vendor)

@versions = versions | args
@versions = versions | requested_versions

if block_given?
within_namespace do
namespace_inheritable(:version, args)
namespace_inheritable(:version, requested_versions)
namespace_inheritable(:version_options, options)

instance_eval(&block)
end
else
namespace_inheritable(:version, args)
namespace_inheritable(:version, requested_versions)
namespace_inheritable(:version_options, options)
end
end
Expand Down
21 changes: 16 additions & 5 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,27 @@ def subject.enable_root_route!

describe 'path versioned APIs' do
before do
subject.version 'v1', using: :path
subject.version version, using: :path
subject.enable_root_route!
end

it 'without a format' do
versioned_get '/', 'v1', using: :path
context 'when a single version provided' do
let(:version) { 'v1' }

it 'without a format' do
versioned_get '/', 'v1', using: :path
end

it 'with a format' do
get '/v1/.json'
end
end

it 'with a format' do
get '/v1/.json'
context 'when array of versions provided' do
let(:version) { %w(v1 v2) }

it { versioned_get '/', 'v1', using: :path }
it { versioned_get '/', 'v2', using: :path }
end
end

Expand Down

0 comments on commit 4d1883f

Please sign in to comment.