Merge commit 'jrun/master'

Conflicts:
	.gitignore
This commit is contained in:
Bryan Helmkamp 2008-11-13 22:40:05 -05:00
commit e8c9f04a19
3 changed files with 41 additions and 8 deletions

2
.gitignore vendored
View File

@ -5,4 +5,4 @@ doc
ri
email.txt
.svn
log

View File

@ -1,27 +1,39 @@
require "mechanize"
module Webrat
class MechanizeSession < Session #:nodoc:
class MechanizeSession < Session
attr_accessor :response
alias :page :response
def initialize(mechanize = WWW::Mechanize.new)
super()
@mechanize = mechanize
end
def get(url, data)
@mechanize_page = @mechanize.get(url, data)
def get(url, data, headers_argument_not_used = nil)
@response = @mechanize.get(url, data)
end
def post(url, data)
@mechanize_page = @mechanize.post(url, data)
def post(url, data, headers_argument_not_used = nil)
post_data = data.inject({}) do |memo, param|
case param.last
when Hash
param.last.each {|attribute, value| memo["#{param.first}[#{attribute}]"] = value }
else
memo[param.first] = param.last
end
memo
end
@response = @mechanize.post(url, post_data)
end
def response_body
@mechanize_page.content
@response.content
end
def response_code
@mechanize_page.code.to_i
@response.code.to_i
end
end

View File

@ -12,4 +12,25 @@ describe Webrat::MechanizeSession do
@mech.headers.should == {}
end
end
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
mechanize = mock :mechanize
mechanize.should_receive(:post).with(url, flattened_data)
Webrat::MechanizeSession.new(mechanize).post(url, data)
end
end
end