|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Grape::Endpoint do |
| 4 | + subject { Class.new(Grape::API) } |
| 5 | + |
| 6 | + def app |
| 7 | + subject |
| 8 | + end |
| 9 | + |
| 10 | + context 'get' do |
| 11 | + it 'routes to a namespace param with dots' do |
| 12 | + subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^\/]+} } do |
| 13 | + get '/' do |
| 14 | + params[:ns_with_dots] |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + get '/test.id.with.dots' |
| 19 | + expect(last_response.status).to eq 200 |
| 20 | + expect(last_response.body).to eq 'test.id.with.dots' |
| 21 | + end |
| 22 | + |
| 23 | + it 'routes to a path with multiple params with dots' do |
| 24 | + subject.get ':id_with_dots/:another_id_with_dots', requirements: { id_with_dots: %r{[^\/]+}, |
| 25 | + another_id_with_dots: %r{[^\/]+} } do |
| 26 | + "#{params[:id_with_dots]}/#{params[:another_id_with_dots]}" |
| 27 | + end |
| 28 | + |
| 29 | + get '/test.id/test2.id' |
| 30 | + expect(last_response.status).to eq 200 |
| 31 | + expect(last_response.body).to eq 'test.id/test2.id' |
| 32 | + end |
| 33 | + |
| 34 | + it 'routes to namespace and path params with dots, with overridden requirements' do |
| 35 | + subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^\/]+} } do |
| 36 | + get ':another_id_with_dots', requirements: { ns_with_dots: %r{[^\/]+}, |
| 37 | + another_id_with_dots: %r{[^\/]+} } do |
| 38 | + "#{params[:ns_with_dots]}/#{params[:another_id_with_dots]}" |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + get '/test.id/test2.id' |
| 43 | + expect(last_response.status).to eq 200 |
| 44 | + expect(last_response.body).to eq 'test.id/test2.id' |
| 45 | + end |
| 46 | + |
| 47 | + it 'routes to namespace and path params with dots, with merged requirements' do |
| 48 | + subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^\/]+} } do |
| 49 | + get ':another_id_with_dots', requirements: { another_id_with_dots: %r{[^\/]+} } do |
| 50 | + "#{params[:ns_with_dots]}/#{params[:another_id_with_dots]}" |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + get '/test.id/test2.id' |
| 55 | + expect(last_response.status).to eq 200 |
| 56 | + expect(last_response.body).to eq 'test.id/test2.id' |
| 57 | + end |
| 58 | + end |
| 59 | +end |
0 commit comments