Skip to content

Commit

Permalink
Support forwarding headers when following redirects when using the Si…
Browse files Browse the repository at this point in the history
…natraSession
  • Loading branch information
joshknowles committed Dec 25, 2008
1 parent d0504d9 commit 89e9ea9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/webrat/sinatra.rb
Expand Up @@ -11,10 +11,9 @@ class SinatraSession < RackSession #:nodoc:
path, data, headers = *args
params = data.merge({:env => headers || {}})
self.__send__("#{verb}_it", path, params)
follow! while @response.redirect?
get_it(@response.location, params) while @response.redirect?
end
end

end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/webrat/sinatra/sinatra_spec.rb
Expand Up @@ -29,6 +29,16 @@
@sinatra_session.should_receive(:delete_it).with("url", { :env => "headers" })
@sinatra_session.delete("url", {}, "headers")
end

it "should forward headers when following redirects" do
@response.should_receive(:redirect?).twice.and_return(true, false)
@response.should_receive(:location).and_return("redirect url")

@sinatra_session.should_receive(:get_it).with("original url", { :env => "headers" })
@sinatra_session.should_receive(:get_it).with("redirect url", { :env => "headers" })

@sinatra_session.get("original url", {}, "headers")
end
end

# Hack required to reset configuration mode to play nice with other specs that depend on this being rails
Expand Down

0 comments on commit 89e9ea9

Please sign in to comment.