Fix #112 Multiple redirections detection

This commit is contained in:
erwanlr
2013-01-19 15:03:58 +01:00
parent 9b34b6597f
commit 0b5d7ad147
3 changed files with 28 additions and 4 deletions

View File

@@ -112,12 +112,29 @@ shared_examples_for "WebSite" do
[301, 302].each do |status_code|
it "should return http://new-location.com if the status code is #{status_code}" do
new_location = "http://new-location.com"
stub_request(:get, web_site.url).
to_return(:status => status_code, :headers => {:location => "http://new-location.com"})
to_return(:status => status_code, :headers => { :location => new_location })
stub_request(:get, new_location).to_return(:status => 200)
web_site.redirection.should === "http://new-location.com"
end
end
context "when multiple redirections" do
it "should return the last redirection" do
first_redirection = "www.redirection.com"
last_redirection = "redirection.com"
stub_request(:get, web_site.url).to_return(:status => 301, :headers => { :location => first_redirection })
stub_request(:get, first_redirection).to_return(:status => 302, :headers => { :location => last_redirection })
stub_request(:get, last_redirection).to_return(:status => 200)
web_site.redirection.should === last_redirection
end
end
end
describe "#page_hash" do

View File

@@ -77,7 +77,8 @@ describe WpTarget do
it "should return the redirection url if there is one (ie: for https)" do
https_login_url = login_url.gsub(/^http:/, "https:")
stub_request(:get, login_url).to_return(:status => 302, :headers => {:location => https_login_url})
stub_request(:get, login_url).to_return(:status => 302, :headers => { :location => https_login_url })
stub_request(:get, https_login_url).to_return(:status => 200)
@wp_target.login_url.should === https_login_url
end