Skip to content

Commit 309321c

Browse files
author
Michael Bleigh
committed
Merge pull request ruby-grape#121 from LTe/patch-method
Support for patch method
2 parents 34de917 + 4e8b118 commit 309321c

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

lib/grape/api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ def put(paths = ['/'], options = {}, &block); route('PUT', paths, options, &bloc
294294
def head(paths = ['/'], options = {}, &block); route('HEAD', paths, options, &block) end
295295
def delete(paths = ['/'], options = {}, &block); route('DELETE', paths, options, &block) end
296296
def options(paths = ['/'], options = {}, &block); route('OPTIONS', paths, options, &block) end
297+
def patch(paths = ['/'], options = {}, &block); route('PATCH', paths, options, &block) end
297298

298299
def namespace(space = nil, &block)
299300
if space || block_given?

spec/grape/api_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ def app; subject end
257257
"lol"
258258
end
259259

260-
%w(get post put delete options).each do |m|
260+
%w(get post put delete options patch).each do |m|
261261
send(m, '/abc')
262262
last_response.body.should eql 'lol'
263263
end
264264
end
265265

266-
verbs = %w(post get head delete put options)
266+
verbs = %w(post get head delete put options patch)
267267
verbs.each do |verb|
268268
it "should allow and properly constrain a #{verb.upcase} method" do
269269
subject.send(verb, '/example') do

spec/grape/endpoint_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def memoized
217217
end
218218

219219
context 'anchoring' do
220-
verbs = %w(post get head delete put options)
220+
verbs = %w(post get head delete put options patch)
221221

222222
verbs.each do |verb|
223223
it "should allow for the anchoring option with a #{verb.upcase} method" do

spec/spec_helper.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
require 'hashie/hash'
1919

20-
RSpec.configure do |config|
21-
config.include Rack::Test::Methods
22-
end
23-
2420
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each do |file|
2521
require file
2622
end
2723

24+
RSpec.configure do |config|
25+
config.include Rack::Test::Methods
26+
config.include Rack::Test::Methods::Patch
27+
end
28+

spec/support/rack_patch.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
unless Rack::Test::Session.method_defined?(:patch)
2+
module Rack
3+
module Test
4+
module Methods
5+
module Patch
6+
extend Forwardable
7+
def_delegators :current_session, *[:patch]
8+
end
9+
end
10+
end
11+
end
12+
13+
module Rack
14+
module Test
15+
class Session
16+
def patch(uri, params = {}, env = {}, &block)
17+
env = env_for(uri, env.merge(:method => "PATCH", :params => params))
18+
process_request(uri, env, &block)
19+
end
20+
end
21+
end
22+
end
23+
else
24+
raise LoadError, "Remove spec/support/rack_patch.rb | rack-test #{Rack::Test::VERSION} has a method patch"
25+
end

0 commit comments

Comments
 (0)