Hi, I have a feature test to test the addition of a ‘publication’ object. For some resean Capybara doesn’t select the research project from the select box.
My feature test looks like this:
background do
@publication = Fabricate(:publication)
admin = Fabricate(:admin)
sign_in(admin)
visit admin_publications_path
end
scenario 'admin adds a new publication' do
@research_project = Fabricate(:research_project)
expect{
find("input[@value='Add Publication']").click
fill_in 'Title', with: @publication.title
fill_in 'Reference', with: @publication.reference
select @research_project.title, :from => 'publication_research_project_id'
click_button 'Add Publication'
}.to change(Publication, :count).by(1)
expect(page).to have_css 'p', text: "You successfully added a publication"
expect(@publication.research_project.title).to eq(@research_project.title)
end
My form looks like this:
<%= form_for [:admin, @publication] do |f| %>
<div>
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<div>
<%= f.label :reference %>
<%= f.text_area :reference %>
</div>
<div>
<%= f.label :research_project %>
<%= f.collection_select :research_project_id, ResearchProject.all, :id, :title, prompt: true %>
</div>
<% if @publication.new_record? %>
<%= f.submit "Add Publication" %>
<% else %>
<%= f.submit "Update Publication" %>
<% end %>
<%= link_to 'Cancel', admin_publications_path %>
<% end %>
Does anyone have a clue what the problem could be?
Thanks for your help,
Anthony