2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
2012-01-04 10:33:41 -05:00
|
|
|
before :all do
|
|
|
|
@servers = 2.times.map { Capybara::Server.new(TestApp.clone).boot }
|
|
|
|
# sanity check
|
|
|
|
@servers[0].port.should_not == @servers[1].port
|
|
|
|
@servers.map { |s| s.port }.should_not include 80
|
|
|
|
end
|
|
|
|
|
|
|
|
def bases
|
|
|
|
@servers.map { |s| "http://#{s.host}:#{s.port}" }
|
2009-12-17 12:41:05 -05:00
|
|
|
end
|
2010-07-09 21:11:54 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
def should_be_on server_index, path="/host", scheme="http"
|
|
|
|
# Check that we are on /host on the given server
|
|
|
|
s = @servers[server_index]
|
|
|
|
@session.current_url.chomp('?').should == "#{scheme}://#{s.host}:#{s.port}#{path}"
|
|
|
|
@session.current_host.should == "#{scheme}://#{s.host}" # no port
|
|
|
|
@session.current_path.should == path
|
|
|
|
if path == '/host'
|
|
|
|
# Server should agree with us
|
2012-08-30 09:58:28 -04:00
|
|
|
@session.should have_content("Current host is #{scheme}://#{s.host}:#{s.port}")
|
2012-01-04 10:33:41 -05:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2012-01-04 10:33:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
def visit_host_links
|
|
|
|
@session.visit("#{bases[0]}/host_links?absolute_host=#{bases[1]}")
|
|
|
|
end
|
2012-01-04 10:33:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "is affected by visiting a page directly" do
|
|
|
|
@session.visit("#{bases[0]}/host")
|
|
|
|
should_be_on 0
|
|
|
|
end
|
2012-01-04 10:33:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "returns to the app host when visiting a relative url" do
|
|
|
|
Capybara.app_host = bases[1]
|
|
|
|
@session.visit("#{bases[0]}/host")
|
|
|
|
should_be_on 0
|
|
|
|
@session.visit('/host')
|
|
|
|
should_be_on 1
|
|
|
|
Capybara.app_host = nil
|
|
|
|
end
|
2012-01-04 10:33:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "is affected by setting Capybara.app_host" do
|
|
|
|
Capybara.app_host = bases[0]
|
|
|
|
@session.visit("/host")
|
|
|
|
should_be_on 0
|
|
|
|
Capybara.app_host = bases[1]
|
|
|
|
@session.visit("/host")
|
|
|
|
should_be_on 1
|
|
|
|
Capybara.app_host = nil
|
|
|
|
end
|
2012-01-04 10:33:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "is unaffected by following a relative link" do
|
|
|
|
visit_host_links
|
|
|
|
@session.click_link("Relative Host")
|
|
|
|
should_be_on 0
|
|
|
|
end
|
2012-01-04 10:33:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "is affected by following an absolute link" do
|
|
|
|
visit_host_links
|
|
|
|
@session.click_link("Absolute Host")
|
|
|
|
should_be_on 1
|
|
|
|
end
|
2012-01-04 10:33:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "is unaffected by posting through a relative form" do
|
|
|
|
visit_host_links
|
|
|
|
@session.click_button("Relative Host")
|
|
|
|
should_be_on 0
|
|
|
|
end
|
2012-01-04 10:33:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "is affected by posting through an absolute form" do
|
|
|
|
visit_host_links
|
|
|
|
@session.click_button("Absolute Host")
|
|
|
|
should_be_on 1
|
|
|
|
end
|
2012-01-04 10:33:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "is affected by following a redirect" do
|
|
|
|
@session.visit("#{bases[0]}/redirect")
|
|
|
|
should_be_on 0, "/landed"
|
2010-07-09 21:11:54 -04:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
|
|
|
|
it "is affected by pushState", :requires => [:js] do
|
|
|
|
@session.visit("/with_js")
|
|
|
|
@session.execute_script("window.history.pushState({}, '', '/pushed')")
|
|
|
|
@session.current_path.should == "/pushed"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is affected by replaceState", :requires => [:js] do
|
|
|
|
@session.visit("/with_js")
|
|
|
|
@session.execute_script("window.history.replaceState({}, '', '/replaced')")
|
|
|
|
@session.current_path.should == "/replaced"
|
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|