2008-10-25 16:59:21 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2008-10-22 01:33:49 +00:00
|
|
|
|
2008-12-26 04:25:27 +00:00
|
|
|
require "webrat/mechanize"
|
|
|
|
|
|
|
|
describe Webrat::MechanizeSession do
|
|
|
|
before :each do
|
2008-12-26 04:04:41 +00:00
|
|
|
Webrat.configuration.mode = :mechanize
|
2008-12-25 17:03:05 +00:00
|
|
|
end
|
2008-12-26 04:04:41 +00:00
|
|
|
|
2008-10-22 01:33:49 +00:00
|
|
|
before(:each) do
|
|
|
|
@mech = Webrat::MechanizeSession.new
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "headers method" do
|
|
|
|
it "should return empty headers for a newly initialized session" do
|
|
|
|
@mech.headers.should == {}
|
|
|
|
end
|
|
|
|
end
|
2008-11-08 14:46:14 +00:00
|
|
|
|
|
|
|
describe "post" do
|
|
|
|
def url
|
|
|
|
'http://test.host/users'
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
{:user => {:first_name => 'Nancy', :last_name => 'Callahan'}}
|
|
|
|
end
|
|
|
|
|
|
|
|
def flattened_data
|
|
|
|
{'user[first_name]' => 'Nancy', 'user[last_name]' => 'Callahan'}
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should flatten model post data" do
|
2008-11-23 04:49:12 +00:00
|
|
|
mechanize = mock(:mechanize)
|
|
|
|
WWW::Mechanize.stub!(:new => mechanize)
|
2008-11-08 14:46:14 +00:00
|
|
|
mechanize.should_receive(:post).with(url, flattened_data)
|
2008-11-23 04:49:12 +00:00
|
|
|
Webrat::MechanizeSession.new.post(url, data)
|
2008-11-08 14:46:14 +00:00
|
|
|
end
|
|
|
|
end
|
2008-12-09 14:59:25 +00:00
|
|
|
|
|
|
|
describe "#absolute_url" do
|
|
|
|
before(:each) do
|
|
|
|
@session = Webrat::MechanizeSession.new
|
|
|
|
@session.stub!(:current_url).and_return(absolute_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def absolute_url
|
|
|
|
'http://test.host/users/fred/cabbages'
|
|
|
|
end
|
|
|
|
|
|
|
|
def rooted_url
|
|
|
|
'/users/fred/cabbages'
|
|
|
|
end
|
|
|
|
|
|
|
|
def relative_url
|
|
|
|
'../../wilma'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should return unmodified url if prefixed with scheme" do
|
|
|
|
@session.absolute_url(absolute_url).should == absolute_url
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should prefix scheme and hostname if url begins with /" do
|
|
|
|
@session.absolute_url(rooted_url).should == absolute_url
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should resolve sibling URLs relative to current path" do
|
|
|
|
@session.absolute_url(relative_url).should == 'http://test.host/users/wilma'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should cope with sibling URLs from root of site" do
|
|
|
|
@session.stub!(:current_url).and_return('http://test.host')
|
|
|
|
@session.absolute_url(relative_url).should == 'http://test.host/wilma'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should cope with https" do
|
|
|
|
@session.stub!(:current_url).and_return('https://test.host')
|
|
|
|
@session.absolute_url(relative_url).should == 'https://test.host/wilma'
|
|
|
|
end
|
|
|
|
end
|
2008-10-22 01:33:49 +00:00
|
|
|
end
|