Formtastic checkbox parameters passed differently by Capybara than the actual application

The checkbox is selected in the form field of the format form:

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

sends bad parameters for: services on the Cucumber test using Capybara, which makes the check unsuccessful, while the actual application sends the correct messages, which are processed normally:

 #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"]} 

Although the html form itself is displayed the same in both cases:

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

It seems that somewhere during the creation of params of the request, the key / value pair pairs for this field are handled differently if they are represented by Cucumber / Capybara.

Anyone else run into this?

+6
ruby-on-rails cucumber capybara formtastic
source share
1 answer

Answering my own question:

Got a pointer from the author of Capybara Jonas Nicklas, which led me to this patch, which has not yet been fixed

For now, I just use 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 assume that this patch will be merged very soon, although it was introduced a couple of months ago.

+1
source share

All Articles