From c49e23d81d365705e6b821ae3bc4e60729a04662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Gil?= Date: Mon, 5 Apr 2010 11:31:38 -0300 Subject: [PATCH] fixes #341 attach_file with nested attributes --- lib/webrat/core/elements/form.rb | 2 +- spec/private/rails/attaches_file_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/webrat/core/elements/form.rb b/lib/webrat/core/elements/form.rb index 1a9b5e6..5ab345c 100644 --- a/lib/webrat/core/elements/form.rb +++ b/lib/webrat/core/elements/form.rb @@ -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 diff --git a/spec/private/rails/attaches_file_spec.rb b/spec/private/rails/attaches_file_spec.rb index e044db0..8d1445c 100644 --- a/spec/private/rails/attaches_file_spec.rb +++ b/spec/private/rails/attaches_file_spec.rb @@ -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 + webrat_session.should_receive(:post).with("/albums", { "album" => { "photos_attributes" => [{"image" => @uploaded_file}] } }) + attach_file "Photo", @filename + click_button + end end