Support forwarding headers when following redirects when using the SinatraSession

This commit is contained in:
Josh Knowles 2008-12-25 18:28:54 -05:00
parent d0504d9344
commit 89e9ea91e9
2 changed files with 11 additions and 2 deletions

View File

@ -11,10 +11,9 @@ module Webrat
path, data, headers = *args path, data, headers = *args
params = data.merge({:env => headers || {}}) params = data.merge({:env => headers || {}})
self.__send__("#{verb}_it", path, params) self.__send__("#{verb}_it", path, params)
follow! while @response.redirect? get_it(@response.location, params) while @response.redirect?
end end
end end
end end
end end

View File

@ -29,6 +29,16 @@ describe Webrat::SinatraSession do
@sinatra_session.should_receive(:delete_it).with("url", { :env => "headers" }) @sinatra_session.should_receive(:delete_it).with("url", { :env => "headers" })
@sinatra_session.delete("url", {}, "headers") @sinatra_session.delete("url", {}, "headers")
end 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 end
# Hack required to reset configuration mode to play nice with other specs that depend on this being rails # Hack required to reset configuration mode to play nice with other specs that depend on this being rails