ruby on rails - capybara not passing select parameters -
i testing form in rails app using capybara.
the form has 2 select boxes, each default options. these options passed parameters when form submitted in development , production, reason capybara not submitting them in testing. capybara finding select boxes , options ok, because if put in non-existent options in throws error. capybara not pass either default or selected option parameter when submits form.
the form snippet follows:
<%= form_for(@reservation, :url => account_reservations_path(account.id), remote: false, :html=>{:id=>'dates_form'}) |f| %> <tr> <td style:"text-align:center" colspan="2"><%= f.submit 'submit dates, source of booking & room preference', class: "btn btn-primary btn-sm" %></td> </tr> <td> <%= f.text_field :check_in_date, id: check_in_date_id, placeholder: "check in date" %></td> <td><%= f.text_field :check_out_date, id: check_out_date_id, placeholder: "check out date" %></td> </tr> <tr> <td colspan="1"><%= f.select(:source_of_booking, reservation::source_of_booking, {}, {:style => "width:150px;", default: reservation::source_of_booking[0]}) %></td> <td> <%= f.select(:bed_preference, @bed_options, {}, {:style => "width:100px;"}) %> </td> </tr> <% end %>
the processing of form submission rails server follows:
processing reservationscontroller#create html
parameters: {"utf8"=>"✓", "authenticity_token"=>"7q3jakpp91blewe1qzqfgrvytxixj9adiybevtrf3bg=", "commit"=>"submit dates, source of booking & room preference", "reservation"=>{"check_in_date"=>"friday, 29 july, 2016", "check_out_date"=>"monday, 1 august, 2016", "source_of_booking"=>"email direct", "bed_preference"=>"queen"}, "account_id"=>"5015"}
but in capybara parameters select options missing, though have default values
started post "/accounts/625262370/reservations" 127.0.0.1 @ 2016-07-25 18:23:59 -0500
processing reservationscontroller#create html parameters: {"utf8"=>"✓", "reservation"=>{"check_in_date"=>"2016-07-25", "check_out_date"=>"2016-07-28"}, "commit"=>"submit dates, source of booking & room preference", "account_id"=>"625262370"}
the test code throws no error until final expect page have text confirmed, capybara finding select box not processing it.
it "should add new reservation room category", :focus => true fill_in('reservation[check_in_date]', :with => date.today.to_s) fill_in('reservation[check_out_date]', :with => (date.today + 3).to_s) select 'twin', :from => 'reservation[bed_preference]' click_button("submit dates, source of booking & room preference") expect(page).to have_text("confirmed") end
depending on driver and/or browser you're using during testing, invalid html can/will interpreted differently. form snippet have generate <form> element <tr> elements children (you appear missing start tr
element around date elements). <form> elements not valid children of <tr> elements , <tr> elements valid children of <table>, <thead>, <tbody>, , <tfoot> elements, valid snippet have like
<%= form_for(@reservation, :url => account_reservations_path(account.id), remote: false, :html=>{:id=>'dates_form'}) |f| %> <table> <tr> <td style:"text-align:center" colspan="2"><%= f.submit 'submit dates, source of booking & room preference', class: "btn btn-primary btn-sm" %></td> </tr> <tr> <td><%= f.text_field :check_in_date, id: check_in_date_id, placeholder: "check in date" %></td> <td><%= f.text_field :check_out_date, id: check_out_date_id, placeholder: "check out date" %></td> </tr> <tr> <td colspan="1"><%= f.select(:source_of_booking, reservation::source_of_booking, {}, {:style => "width:150px;", default: reservation::source_of_booking[0]}) %></td> <td> <%= f.select(:bed_preference, @bed_options, {}, {:style => "width:100px;"}) %></td> </tr> </table> <% end %>
without valid html it's possible fields considered outside form , therefore not submitted it. i'm guessing using chrome dev , production systems since tends lot more lenient in interpretation of invalid tables , if try firefox on dev , production systems you'll find doesn't work since tends lot less lenient invalid tables.
Comments
Post a Comment