Merge remote branch 'wemrysi/master' into mechanize_redirects
Conflicts: lib/webrat/adapters/mechanize.rb
This commit is contained in:
commit
38e699820f
@ -41,8 +41,16 @@ module Webrat #:nodoc:
|
|||||||
@response.code.to_i
|
@response.code.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def response_headers
|
||||||
|
@response.header
|
||||||
|
end
|
||||||
|
|
||||||
def mechanize
|
def mechanize
|
||||||
@mechanize ||= Mechanize.new
|
@mechanize ||= begin
|
||||||
|
mechanize = Mechanize.new
|
||||||
|
mechanize.redirect_ok = false
|
||||||
|
mechanize
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def_delegators :mechanize, :basic_auth
|
def_delegators :mechanize, :basic_auth
|
||||||
|
@ -18,6 +18,10 @@ module Webrat
|
|||||||
response.status
|
response.status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def response_headers
|
||||||
|
response.headers
|
||||||
|
end
|
||||||
|
|
||||||
def response
|
def response
|
||||||
@session.last_response
|
@session.last_response
|
||||||
end
|
end
|
||||||
|
@ -35,6 +35,10 @@ module Webrat
|
|||||||
response.code.to_i
|
response.code.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def response_headers
|
||||||
|
response.headers
|
||||||
|
end
|
||||||
|
|
||||||
def xml_content_type?
|
def xml_content_type?
|
||||||
response.headers["Content-Type"].to_s =~ /xml/
|
response.headers["Content-Type"].to_s =~ /xml/
|
||||||
end
|
end
|
||||||
|
@ -282,7 +282,7 @@ For example:
|
|||||||
end
|
end
|
||||||
|
|
||||||
def response_location
|
def response_location
|
||||||
response.headers["Location"]
|
response_headers['Location']
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_host
|
def current_host
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||||
|
|
||||||
describe Webrat::MechanizeAdapter do
|
describe Webrat::MechanizeAdapter do
|
||||||
|
|
||||||
|
Mechanize = WWW::Mechanize if defined?(WWW::Mechanize)
|
||||||
|
|
||||||
before :each do
|
before :each do
|
||||||
Webrat.configuration.mode = :mechanize
|
Webrat.configuration.mode = :mechanize
|
||||||
end
|
end
|
||||||
@ -9,6 +12,13 @@ describe Webrat::MechanizeAdapter do
|
|||||||
@mech = Webrat::MechanizeAdapter.new
|
@mech = Webrat::MechanizeAdapter.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
describe "post" do
|
describe "post" do
|
||||||
def url
|
def url
|
||||||
'http://test.host/users'
|
'http://test.host/users'
|
||||||
@ -24,7 +34,8 @@ describe Webrat::MechanizeAdapter do
|
|||||||
|
|
||||||
it "should flatten model post data" do
|
it "should flatten model post data" do
|
||||||
mechanize = mock(:mechanize)
|
mechanize = mock(:mechanize)
|
||||||
WWW::Mechanize.stub!(:new => mechanize)
|
mechanize.stub!(:redirect_ok=)
|
||||||
|
Mechanize.stub!(:new => mechanize)
|
||||||
mechanize.should_receive(:post).with(url, flattened_data)
|
mechanize.should_receive(:post).with(url, flattened_data)
|
||||||
Webrat::MechanizeAdapter.new.post(url, data)
|
Webrat::MechanizeAdapter.new.post(url, data)
|
||||||
end
|
end
|
||||||
@ -70,4 +81,16 @@ describe Webrat::MechanizeAdapter do
|
|||||||
@session.absolute_url(relative_url).should == 'https://test.host/wilma'
|
@session.absolute_url(relative_url).should == 'https://test.host/wilma'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user