ruby on rails - Capybara won't fill in fields -
i new capybara (using 2.1.0) , cannot fill in fields in brand-new (rails 4/ruby 2) application. since it's started, app simple.
for user#new, fill in 1 field, has validation, , saves when it's valid , fails when it's not. great. have model, , try coireport#new , not work.
it keeps failing "owner cannot empty" (it's got validate_presence_of validator) though if save_and_open_page before click_button "create new" field filled in. field field, thought might it, when changed type="text" still fails. works when hand.
so both of these simple forms, 1 works , 1 doesn't , can't think difference is!
here's form:
<%= form_for(@coi_record) |f| %> <% if @coi_record.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@coi_record.errors.count, "error") %> prohibited coi_record being saved:</h2> <ul> <% @coi_record.errors.full_messages.each |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :owner_id %><br> <%= f.text_field :owner_id %> </div> <div class="field"> <%= f.label :signer_id %><br> <%= f.text_field :signer_id %> </div> <div class="field"> <%= f.label :signed_at %><br> <%= f.datetime_select :signed_at %> </div> <div class="field"> <%= f.label :is_current %><br> <%= f.check_box :is_current %> </div> <div class="field"> <%= f.label :has_no_conflicts %><br> <%= f.check_box :has_no_conflicts %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> and here's test:
require 'spec_helper' describe 'test2' "should work!" visit '/coi_records/new' page.should have_content('new coi_record') within '#new_coi_record' fill_in 'owner', :with => '1' check 'is current' check 'has no conflicts' click_button 'create coi record' end # save_and_open_page page.should have_content('coi record created.') end end help!
ok simple pilot error on part. depa absolutely correct not capybara problem. problem validator. coirecord associated user thusly:
belongs_to :owner, class_name: 'user' i wanted required relation, had validation, in coirecord,
validates_presence_of :owner where should
validates_presence_of :owner_id changing lets test pass. rookie error. how embarrassing! of course looked @ 100 times , not see it. depa pointed way, see value being set, had wonder, why validation fail anyway...?
though have been nice if rails had noticed , reported requirement of field doesn't exist...?
Comments
Post a Comment