Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add patch verb #30

Merged
merged 1 commit into from
Oct 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/api_taster/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def put(path, params = {}, metadata = {})
map_method(:put, path, params, metadata)
end

def patch(path, params = {}, metadata = {})
map_method(:patch, path, params, metadata)
end

def delete(path, params = {}, metadata = {})
map_method(:delete, path, params, metadata)
end
Expand Down
13 changes: 12 additions & 1 deletion spec/mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ module ApiTaster
end

before(:all) do
Rails.application.routes.draw { resources :dummy_users }
Rails.application.routes.draw do
resources :dummy_users do
member { map_method :patch, :update }
end
end
end

context "#global_params" do
Expand Down Expand Up @@ -52,6 +56,7 @@ module ApiTaster
post '/dummy_users', { :hello => 'world' }, { :meta => 'data' }
put '/dummy_users/:id', :id => 2
delete '/dummy_users/:id', :id => 3
patch '/dummy_users/:id', :id => 4
end

Route.map_routes
Expand All @@ -75,6 +80,12 @@ module ApiTaster
Route.supplied_params[route[:id]].should == [{ :id => 2 }]
end

it "edits a user via PATCH" do
route = Route.find_by_verb_and_path(:patch, '/dummy_users/:id')

Route.supplied_params[route[:id]].should == [{ :id => 4 }]
end

it "deletes a user" do
route = Route.find_by_verb_and_path(:delete, '/dummy_users/:id')

Expand Down