6
votes

The following formtastic form checkbox field set:

<%= semantic_form_for @store do |f| %>
  <%= f.inputs do %>
    <%= f.input :services, :as => :check_boxes, :collection => Service.all %>  
  <% end -%>
<% end -%>

is sending bad params for :services on a Cucumber test using Capybara, making the test fail, while the actual app sends the correct ones, which gets processed fine:

#cucumber steps using the boiler_plate capybara web_steps.rb:
Given a "Mail Order" service
...(steps for rest of the form)...
When I check "Mail Order" 
And I press "Create Store"
Then I should see "Store was successfully created."
And I should see "Mail Order"

#params sent by cucumber
"store"=>{"services"=>["[\"4d8247ed7f5bfd2275000004\"]"]

#params sent by app on manual test
"store"=>{"services"=>["4d8247ed7f5bfd2275000004"]}

Though the html form itself is rendered the same way in both cases:

<input id="store_services_4d8247ed7f5bfd2275000004" name="store[services][]" type="checkbox" value="4d8247ed7f5bfd2275000004" />

Seems like somewhere during the request params-building, the form key/value pairs for that field get parsed differently when submitted by Cucumber/Capybara.

Anyone else come across this?

1
That solution should probably be turned into an "answer" - other people may search for (and find) this problem, but skip over it, thinking there isn't a solution.Taryn East
I couldn't find a way to answer my own question. Might not have enough privileges? I searched the meta site for answers about this, but no luck.oliverbarnes
If you're logged in, you should have a big box just below these comments. Doesn't matter if it's your own question or not.Taryn East
Well, I agree it shouldn't, but it seems to matter... no big box here :/oliverbarnes
hmmm, actually it looks like I've got privileges now :) there's a big "Answer Your Question" link, which wasn't there at the time. Thanks for prodding, wouldn't have looked for it again otherwise.oliverbarnes

1 Answers

1
votes

Answering my own question:

Got a pointer from Capybara's author, Jonas Nicklas, that led me to this rack-test patch which hasn't been committed yet

For now I'm just using the fork and branch where the patch lives:

gem 'rack-test', :git => 'https://github.com/econsultancy/rack-test.git', :branch => 'econsultancy-20110119'

And that does the trick. I imagine this patch will be merged in very soon though, as it was submitted a couple of months ago.