the mechanize session must specially handle params
{:user => {:name => "Nancy"}} now becomes {"user[name]" => "Nancy"}
This commit is contained in:
parent
d039c9590f
commit
7dfd59c29c
@ -15,7 +15,16 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def post(url, data, headers_argument_not_used = nil)
|
def post(url, data, headers_argument_not_used = nil)
|
||||||
@mechanize_page = @mechanize.post(url, data)
|
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
|
||||||
|
@mechanize_page = @mechanize.post(url, post_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def response_body
|
def response_body
|
||||||
|
@ -12,4 +12,25 @@ describe Webrat::MechanizeSession do
|
|||||||
@mech.headers.should == {}
|
@mech.headers.should == {}
|
||||||
end
|
end
|
||||||
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
|
end
|
Loading…
Reference in New Issue
Block a user