webrat fails when file field exists, but is no files are attached.

5 views
Skip to first unread message

Jarl Friis

unread,
May 28, 2010, 8:18:31 AM5/28/10
to web...@googlegroups.com
Hi.

I think webrat is a fantastic tool. However I have found 1 serious
issue, and one minor issue.

When a page contains a file field and no file is uploaded, then a
parameter is generated anyway. This was also the problem with rack
testing some time ago (see
http://rack.lighthouseapp.com/projects/22435/tickets/37).

Here is a minimal patch that solves the problem for webrat (tests
should of course be made

--- /var/lib/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/elements/form.rb.org 2010-05-26 21:11:16.978887686 +0200
+++ /var/lib/gems/1.8/gems/webrat-0.7.1/lib/webrat/core/elements/form.rb 2010-05-26 21:39:40.728106794 +0200
@@ -47,6 +47,7 @@

fields.each do |field|
next if field.to_query_string.nil?
+ next if field.is_a?(FileField) && field.test_uploaded_file.blank?
replaces.merge!({field.digest_value => field.test_uploaded_file}) if field.is_a?(FileField)
query_string << field.to_query_string
end

Jarl

Jarl Friis

unread,
Aug 9, 2010, 9:45:48 AM8/9/10
to web...@googlegroups.com
Jarl Friis <ja...@gavia.dk> writes:

> Hi.
>
> I think webrat is a fantastic tool. However I have found 1 serious
> issue, and one minor issue.
>
> When a page contains a file field and no file is uploaded, then a
> parameter is generated anyway. This was also the problem with rack
> testing some time ago (see
> http://rack.lighthouseapp.com/projects/22435/tickets/37).

This have been comitted to bug 390:
https://webrat.lighthouseapp.com/projects/10503-webrat/tickets/390-webrat-does-not-pass-empty-form-file-fields-correctly-to-rails

Jarl

Reply all
Reply to author
Forward
0 new messages