I am new to Capybara (using 2.1.0) and I cannot get it to fill in some fields in my brand-new (Rails 4/Ruby 2) application. Since it's just started, the app is simple.
For my User#new, I fill in the one field, which has a validation, and it saves when it's valid and fails when it's not. Great. I have another model, and try to do CoiReport#new and it does not work.
It keeps failing with "Owner cannot be empty" (it's got a validate_presence_of validator) even though if I save_and_open_page before click_button "Create New" the field is filled in. The field is an field, so I thought that might be it, but even when I changed it to type="text" it still fails. It also works when I do it by hand.
So both of these are very simple forms, but one works and one doesn't and I can't think what the difference is!
Here's the form:
<%= form_for(@coi_record) do |f| %>
<% if @coi_record.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@coi_record.errors.count, "error") %> prohibited this coi_record from being saved:</h2>
<ul>
<% @coi_record.errors.full_messages.each do |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 the test:
require 'spec_helper'
describe 'test2' do
it "should work!" do
visit '/coi_records/new'
page.should have_content('New coi_record')
within '#new_coi_record' do
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 was successfully created.')
end
end
Help!