Skip to content

Commit

Permalink
Additional fix for mismatching variable names: regression from ruby-g…
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock authored and przbadu committed Apr 5, 2016
1 parent 5f3c2c4 commit c2c81c4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ def add_head_not_allowed_methods_and_options_methods
self.class.endpoints.each do |endpoint|
routes = endpoint.routes
routes.each do |route|
# ignore any optional portions of the path
route_path = route.route_path.gsub(/\(.*\)/, '')
route_path = route.route_path
.gsub(/\(.*\)/, '') # ignore any optional portions
.gsub(%r{\:[^\/.?]+}, ':x') # substitute variable names to avoid conflicts

methods_per_path[route_path] ||= []
methods_per_path[route_path] << route.route_method
Expand Down
37 changes: 37 additions & 0 deletions spec/grape/api/required_parameters_in_route_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper'

describe Grape::Endpoint do
subject { Class.new(Grape::API) }

def app
subject
end

before do
subject.namespace :api do
get ':id' do
[params[:id], params[:ext]].compact.join('/')
end

put ':something_id' do
params[:something_id]
end
end
end

context 'get' do
it 'responds' do
get '/api/foo'
expect(last_response.status).to eq 200
expect(last_response.body).to eq 'foo'
end
end

context 'put' do
it 'responds' do
put '/api/foo'
expect(last_response.status).to eq 200
expect(last_response.body).to eq 'foo'
end
end
end

0 comments on commit c2c81c4

Please sign in to comment.