fixes #341 attach_file with nested attributes

This commit is contained in:
Álvaro Gil 2010-04-05 11:31:38 -03:00
parent 15102bd60d
commit c49e23d81d
2 changed files with 16 additions and 1 deletions

View File

@ -73,7 +73,7 @@ module Webrat
when Hash
value = replace_param_value(value, oval, nval)
when Array
value = value.map { |o| o == oval ? nval : o }
value = value.map { |o| o == oval ? nval : ( o.is_a?(Hash) ? replace_param_value(o, oval, nval) : o) }
when oval
value = nval
end

View File

@ -78,4 +78,19 @@ describe "attach_file" do
attach_file "Picture", @filename, "image/png"
click_button
end
it "should support nested attributes" do
with_html <<-HTML
<html>
<form method="post" action="/albums">
<label for="photo_file1">Photo</label>
<input type="file" id="photo_file1" name="album[photos_attributes][][image]" />
<input type="submit" />
</form>
</html>
HTML
webrat_session.should_receive(:post).with("/albums", { "album" => { "photos_attributes" => [{"image" => @uploaded_file}] } })
attach_file "Photo", @filename
click_button
end
end