jnicklas/capybara — Issue #649: Multiple choice selection box param values returned as array of arrays
Author: hoenth
Created: 2012-02-27 17:59:51+00:00
State: open

I recently began getting an error when running Cucumber specs where a multipart form returned a selection_collection field with multiple => true.

In my case, the selection_collection field relates an object to a habtm relationship.

= f.collection_select :category_ids, categories, :id, :name, {}, :multiple => true

where f is a form for a Cause object.

When the spec hits the controller statement that saves the Cause object, I get the following error:

Couldn't find Category with ID=0 (ActiveRecord::RecordNotFound)
./app/controllers/admin/causes_controller.rb:16:in `update'
:10:in `synchronize'

When I run the same spec using Selenium (setting the @javascript tag) the spec passes.

When run without selenium (and no options in the category_ids field selected), the params object contains:
"category_ids"=>["[\"\"]"]

When run with selelenium, the params object contains:
"category_ids"=>[""]

I have checked the params function in the Capybara::RackTest::Form class and it appears to be correctly returning an array with a single empty string.

I also checked in the Rack::Test module, but can't discern whether the switch to an array of arrays is happening there, or within Capybara (or somewhere else, for that matter).