Skip to content

Commit

Permalink
fixing verb and creating unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Feb 7, 2011
1 parent e7e9671 commit 437e388
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
31 changes: 12 additions & 19 deletions lib/restfulie/client/feature/verb.rb
Expand Up @@ -56,58 +56,51 @@ def delete
# * <tt>path: '/posts'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def get!(params = {})
@verb = :get
at query_string(params)
request :throw_error
request_flow
request :throw_error_request
get params
end

# HEAD HTTP verb {Error}
# * <tt>path: '/posts'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def head!
@verb = :head
request :throw_error
request_flow
request :throw_error_request
head
end

# POST HTTP verb {Error}
# * <tt>path: '/posts'</tt>
# * <tt>payload: 'some text'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def post!(payload, options = {:recipe => nil})
@verb = :post
request :throw_error
request_flow :body => payload
request :throw_error_request
post payload
end

# PATCH HTTP verb {Error}
# * <tt>path: '/posts'</tt>
# * <tt>payload: 'some text'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def patch!(payload)
@verb = :patch
request :throw_error
request_flow :body => payload
request :throw_error_request
patch payload
end

# PUT HTTP verb {Error}
# * <tt>path: '/posts'</tt>
# * <tt>payload: 'some text'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def put!(payload)
@verb = :put
request :throw_error
request_flow :body => payload
request :throw_error_request
put payload
end

# DELETE HTTP verb {Error}
# * <tt>path: '/posts'</tt>
# * <tt>headers: {'Accept' => '*/*', 'Content-Type' => 'application/atom+xml'}</tt>
def delete!
@verb = :delete
request :throw_error
request_flow
request :throw_error_request
delete
end

protected
Expand Down
37 changes: 37 additions & 0 deletions spec/unit/client/feature/verb_spec.rb
@@ -0,0 +1,37 @@
require 'spec_helper'

describe Restfulie::Client::Feature::Verb do

before do
@request = Object.new
@request.extend Restfulie::Client::Feature::Verb
end

context "when invoking throw error based methods" do

it "should invoke throw error and delegate invocations on get" do
@request.should_receive(:request).with(:throw_error_request)
@request.should_receive(:get).with({:key => :value})
@request.get!({:key => :value})
end

["head", "delete"].each do |method|
it "should invoke throw error and delegate invocations on #{method}" do
@request.should_receive(:request).with(:throw_error_request)
@request.should_receive(method)
@request.send "#{method}!"
end
end

["put", "post", "patch"].each do |method|
it "should invoke throw error and delegate invocations on #{method}" do
body = "{ 'data' : 'content' }"
@request.should_receive(:request).with(:throw_error_request)
@request.should_receive(method).with(body)
@request.send "#{method}!", body
end
end

end

end

0 comments on commit 437e388

Please sign in to comment.