forked from ruby-grape/grape
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ruby-grape#1788 from darren987469/fix_route_requir…
…ements_bug Fix route requirements bug
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'spec_helper' | ||
|
||
describe Grape::Endpoint do | ||
subject { Class.new(Grape::API) } | ||
|
||
def app | ||
subject | ||
end | ||
|
||
context 'get' do | ||
it 'routes to a namespace param with dots' do | ||
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^\/]+} } do | ||
get '/' do | ||
params[:ns_with_dots] | ||
end | ||
end | ||
|
||
get '/test.id.with.dots' | ||
expect(last_response.status).to eq 200 | ||
expect(last_response.body).to eq 'test.id.with.dots' | ||
end | ||
|
||
it 'routes to a path with multiple params with dots' do | ||
subject.get ':id_with_dots/:another_id_with_dots', requirements: { id_with_dots: %r{[^\/]+}, | ||
another_id_with_dots: %r{[^\/]+} } do | ||
"#{params[:id_with_dots]}/#{params[:another_id_with_dots]}" | ||
end | ||
|
||
get '/test.id/test2.id' | ||
expect(last_response.status).to eq 200 | ||
expect(last_response.body).to eq 'test.id/test2.id' | ||
end | ||
|
||
it 'routes to namespace and path params with dots, with overridden requirements' do | ||
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^\/]+} } do | ||
get ':another_id_with_dots', requirements: { ns_with_dots: %r{[^\/]+}, | ||
another_id_with_dots: %r{[^\/]+} } do | ||
"#{params[:ns_with_dots]}/#{params[:another_id_with_dots]}" | ||
end | ||
end | ||
|
||
get '/test.id/test2.id' | ||
expect(last_response.status).to eq 200 | ||
expect(last_response.body).to eq 'test.id/test2.id' | ||
end | ||
|
||
it 'routes to namespace and path params with dots, with merged requirements' do | ||
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^\/]+} } do | ||
get ':another_id_with_dots', requirements: { another_id_with_dots: %r{[^\/]+} } do | ||
"#{params[:ns_with_dots]}/#{params[:another_id_with_dots]}" | ||
end | ||
end | ||
|
||
get '/test.id/test2.id' | ||
expect(last_response.status).to eq 200 | ||
expect(last_response.body).to eq 'test.id/test2.id' | ||
end | ||
end | ||
end |