开发者

Formtastic checkbox params sent differently by Capybara than by actual app

开发者 https://www.devze.com 2023-02-18 05:41 出处:网络
The following formtastic form checkbox field set: <%= semantic_form_for @store do |f| %> <%= f.inputs 开发者_运维问答do %>

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消