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
|
|
|
|
2009-08-13 00:54:27 +00:00
|
|
|
describe Webrat::MechanizeAdapter do
|
2008-12-26 04:25:27 +00:00
|
|
|
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
|
2009-08-13 00:54:27 +00:00
|
|
|
@mech = Webrat::MechanizeAdapter.new
|
2008-10-22 01:33:49 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2010-02-19 00:04:11 +00:00
|
|
|
describe "mechanize" do
|
|
|
|
it "should disable the following of redirects on the mechanize instance" do
|
|
|
|
mech = @mech.mechanize
|
|
|
|
mech.redirect_ok.should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-11-08 14:46:14 +00:00
|
|
|
describe "post" do
|
|
|
|
def url
|
|
|
|
'http://test.host/users'
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-08 14:46:14 +00:00
|
|
|
def data
|
|
|
|
{:user => {:first_name => 'Nancy', :last_name => 'Callahan'}}
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-08 14:46:14 +00:00
|
|
|
def flattened_data
|
|
|
|
{'user[first_name]' => 'Nancy', 'user[last_name]' => 'Callahan'}
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-08 14:46:14 +00:00
|
|
|
it "should flatten model post data" do
|
2008-11-23 04:49:12 +00:00
|
|
|
mechanize = mock(:mechanize)
|
2010-02-19 00:04:11 +00:00
|
|
|
mechanize.stub!(:redirect_ok=)
|
|
|
|
Mechanize.stub!(:new => mechanize)
|
2008-11-08 14:46:14 +00:00
|
|
|
mechanize.should_receive(:post).with(url, flattened_data)
|
2009-08-13 00:54:27 +00:00
|
|
|
Webrat::MechanizeAdapter.new.post(url, data)
|
2008-11-08 14:46:14 +00:00
|
|
|
end
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-09 14:59:25 +00:00
|
|
|
describe "#absolute_url" do
|
|
|
|
before(:each) do
|
2009-08-13 00:54:27 +00:00
|
|
|
@session = Webrat::MechanizeAdapter.new
|
2008-12-09 14:59:25 +00:00
|
|
|
@session.stub!(:current_url).and_return(absolute_url)
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-09 14:59:25 +00:00
|
|
|
def absolute_url
|
|
|
|
'http://test.host/users/fred/cabbages'
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-09 14:59:25 +00:00
|
|
|
def rooted_url
|
|
|
|
'/users/fred/cabbages'
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-09 14:59:25 +00:00
|
|
|
def relative_url
|
|
|
|
'../../wilma'
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-09 14:59:25 +00:00
|
|
|
it "should return unmodified url if prefixed with scheme" do
|
|
|
|
@session.absolute_url(absolute_url).should == absolute_url
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-09 14:59:25 +00:00
|
|
|
it "should prefix scheme and hostname if url begins with /" do
|
|
|
|
@session.absolute_url(rooted_url).should == absolute_url
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-09 14:59:25 +00:00
|
|
|
it "should resolve sibling URLs relative to current path" do
|
|
|
|
@session.absolute_url(relative_url).should == 'http://test.host/users/wilma'
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-09 14:59:25 +00:00
|
|
|
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
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-12-09 14:59:25 +00:00
|
|
|
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
|
2010-02-20 22:06:30 +00:00
|
|
|
|
|
|
|
describe "response_headers" do
|
|
|
|
it "should return the Headers object from the response" do
|
|
|
|
mech = @mech.mechanize
|
|
|
|
resp = mock('Mechanize::File')
|
|
|
|
hdr = Mechanize::Headers.new
|
|
|
|
resp.should_receive(:header).and_return(hdr)
|
|
|
|
mech.stub!(:get).and_return(resp)
|
|
|
|
@mech.get('/', nil)
|
|
|
|
@mech.response_headers.should == hdr
|
|
|
|
end
|
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
end
|