Skip to content

Commit af9911b

Browse files
committed
Add support for patch method.
1 parent 1cad615 commit af9911b

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
@@ -282,6 +282,7 @@ def after(&block)
282282
imbue(:afters, [block])
283283
end
284284

285+
def patch(paths = ['/'], options = {}, &block); route('PATCH', paths, options, &block) end
285286
def get(paths = ['/'], options = {}, &block); route('GET', paths, options, &block) end
286287
def post(paths = ['/'], options = {}, &block); route('POST', paths, options, &block) end
287288
def put(paths = ['/'], options = {}, &block); route('PUT', paths, options, &block) end

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)