Skip to content

Commit

Permalink
Merge pull request #13 from dmargery/follow_redirect
Browse files Browse the repository at this point in the history
Follow redirect : fix for issue #12
  • Loading branch information
crohr committed Jun 11, 2015
2 parents ab7cb88 + 854df40 commit bd0be3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/restfully/session.rb
Expand Up @@ -190,6 +190,9 @@ def process(response, request)
logger.debug "Building response..."
Resource.new(self, response, request).build
when 201,202
logger.debug "Getting description of newly created resource at: #{response.head['Location'].inspect}"
get response.head['Location'], :head => request.head
when 301,302
logger.debug "Following redirection to: #{response.head['Location'].inspect}"
get response.head['Location'], :head => request.head
when 204
Expand Down
13 changes: 13 additions & 0 deletions spec/restfully/session_spec.rb
Expand Up @@ -247,6 +247,19 @@
end
end

[301, 302].each do |status|
it "should fetch the resource specified in the Location header if status = #{status}" do
@response.stub!(:code).and_return(status)
@response.head['Location'] = @uri+"/path"

@session.should_receive(:get).
with(@uri+"/path", :head => @request.head).
and_return(resource=mock("resource"))
@session.process(@response, @request).
should == resource
end
end

it "should return a Restfully::Resource if successful" do
Restfully::MediaType.register Restfully::MediaType::ApplicationJson
body = {
Expand Down

0 comments on commit bd0be3e

Please sign in to comment.