Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mulitple: true submitting wrong value when left empty #1108

Closed
workmaster2n opened this issue Jun 24, 2013 · 2 comments
Closed

Mulitple: true submitting wrong value when left empty #1108

workmaster2n opened this issue Jun 24, 2013 · 2 comments

Comments

@workmaster2n
Copy link

I asked over on SO: http://stackoverflow.com/questions/17170171/capybara-form-with-multiple-true-getting-sent-the-wrong-value

I have a form that uses the multiple: true option to allow me to upload multiple files at a time. I can upload multiple files just fine, but when I run my tests that do not choose a file to upload, my controller crashes because it tries to find a file named "".

Spec:

it "can create region for zone" do
  fill_in "x_coords_1", with: 0
  fill_in "y_coords_1", with: 0
  fill_in "x_coords_2", with: 10
  fill_in "y_coords_2", with: 0
  fill_in "x_coords_3", with: 10
  fill_in "y_coords_3", with: 10
  fill_in "x_coords_4", with: 0
  fill_in "y_coords_4", with: 10
  click_button "Create Zone"
  page.should have_content "Zone was successfully created"
end

Form:

= simple_form_for([@site, @zone], mulitpart: true) do |f|
  = f.error_notification

  .form-inputs
    = f.input :site_id
    = f.input :default_state

    = file_field_tag "zone_shapefiles_asset", multiple: true, name: "zone[shapefiles_attributes][][asset]"
    = label_tag "X"
    = text_field_tag 'x_coords[]', nil, id: "x_coords_1"

    = label_tag "Y"
    = text_field_tag 'y_coords[]', nil, id: "y_coords_1"

    = label_tag "X"
    = text_field_tag 'x_coords[]', nil, id: "x_coords_2"

    = label_tag "Y"
    = text_field_tag 'y_coords[]', nil, id: "y_coords_2"

    = label_tag "X"
    = text_field_tag 'x_coords[]', nil, id: "x_coords_3"

    = label_tag "Y"
    = text_field_tag 'y_coords[]', nil, id: "y_coords_3"

    = label_tag "X"
    = text_field_tag 'x_coords[]', nil, id: "x_coords_4"

    = label_tag "Y"
    = text_field_tag 'y_coords[]', nil, id: "y_coords_4"

    = link_to "Add Point", "#", id: "add_point", data: { fields: label_tags.gsub("\"", "'") }

  .form-actions
    = f.button :submit

Error:
Paperclip::AdapterRegistry::NoHandlerError: No handler found for ""

If I remove the multiple: true declaration from the form, the spec passes just fine.

If I recreate the process myself in a browser, the program works just fine. It's only when running the tests that this field is submitted incorrectly. It appears that instead of submitting the form with zone[shapefiles_attributes][][asset] set to nil, it is submitting the form with a value of "".

ghost pushed a commit that referenced this issue Jul 2, 2013
@jnicklas
Copy link
Collaborator

jnicklas commented Jul 2, 2013

I just added a test case which seems to prove that the form is indeed being submitted with a value of nil, and not "", at least given Sinatra's params parser. Could you please re-check and see if this isn't an issue with your application somewhere?

@workmaster2n
Copy link
Author

There is a typo in my form. It is mulitpart: true instead of multipart: true. Thanks for looking into that and adding the test.

Best of luck

@lock lock bot locked and limited conversation to collaborators Aug 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants