Skip to content

Commit

Permalink
Merge pull request #11 from zrivest/add_support_for_patch_http_method
Browse files Browse the repository at this point in the history
Add support for PATCH http method
  • Loading branch information
gus committed Oct 5, 2015
2 parents 86fcddd + a292df0 commit eac22af
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,5 +1,9 @@
# @markup markdown

# 0.0.15

* Allow PATCH HTTP calls [zrivest]

# 0.0.14

* Allow `denies_json` to deny a string in the reponse json
Expand Down
5 changes: 2 additions & 3 deletions lib/riot/gear/middleware/riotparty.rb
@@ -1,10 +1,9 @@
require 'httparty'

# Here we prepare a {Riot::Context} to have HTTParty bound to it. Basically, this means that you can
# use HTTParty within a context the same way you would inside any class or you would normally use it in.
# Anything you can do with HTTParty, you can do within a context ... and then you can test it :)
#
# Great pains are made to ensure that the HTTParty setup bound to one context does not interfere setup
# Great pains are made to ensure that the HTTParty setup bound to one context does not interfere setup
# bound to another context.
class Riot::Gear::RiotPartyMiddleware < ::Riot::ContextMiddleware
register
Expand Down Expand Up @@ -45,7 +44,7 @@ def setup_faux_class(context)
# Returns the list of methods that do something; like make a network call.
#
# @return [Array<Symbol>]
def actionable_methods; [:get, :post, :put, :delete, :head, :options]; end
def actionable_methods; [:get, :post, :put, :patch, :delete, :head, :options]; end

# Returns the list of methods that configure actionable HTTParty methods. The
# {HTTParty.default_options} method is explicitly excluded from this list
Expand Down
58 changes: 58 additions & 0 deletions test/actions/patch_test.rb
@@ -0,0 +1,58 @@
require 'teststrap'

context "Sending a PATCH request with a base uri" do

context "without params" do
hookup do
stub_request(:patch, 'http://test.local/foo')
.with(:body => {"foo" => "bar"}.to_json)
.to_return(:body => "Foo", :status => 200)
end

base_uri "http://test.local"
patch "/foo", :body => {"foo" => "bar"}.to_json

asserts("status code") { response.code }.equals(200)
asserts("response body") { response.body }.equals("Foo")
end # without params

context "with params" do
hookup do
stub_request(:patch, 'http://test.local/foo?bar=baz').
with(:body => {"goo" => "car"}.to_json).
to_return(:body => "", :status => 203)
end

context "through default_params" do
base_uri "http://test.local"
default_params({"bar" => "baz"})
patch "/foo", :body => {"goo" => "car"}.to_json

asserts("status code") { response.code }.equals(203)
end # through default_params

context "through query string" do
base_uri "http://test.local"
patch "/foo?bar=baz", :body => {"goo" => "car"}.to_json

asserts("status code") { response.code }.equals(203)
end # through query string
end # with params

context "while processing options from a block" do
hookup do
stub_request(:patch, 'http://test.local/foo/bar').
with(:body => {"s" => "things"}.to_json).
to_return(:body => "", :status => 299)
end

base_uri "http://test.local"

patch do
{ :path => "/foo/bar", :body => {"s" => "things"}.to_json }
end

asserts("status code") { response.code }.equals(299)
end # while processing options from a block

end # Sending a PUT request with a base uri

0 comments on commit eac22af

Please sign in to comment.