Afaik you could test for two things:
- that the dynamic addition of the nested elements works
- creating elements, filling it in and storing them in the database
So assume the relevant part of your view looks like this (default example):
#tasks
= f.semantic_fields_for :tasks do |task|
= render 'task_fields', :f => task
.links
= link_to_add_association 'add task', f, :tasks
and your nested element looks like
.nested-fields
= f.input :description
= f.input :done, :as => :boolean
= link_to_remove_association "remove task", f
So normally you give it a class, i normally just test the count of elements on the page.
So if one element is already there, creating a new element, the count should be two. This you could test with
find("#tasks .nested-fields").count.should == 2
Filling in the newly added nested element, you could use the :last-child
css selector
find("#tasks .nested-fields:last-child input#description").set("something")
How names and id are formed, are close to rails internals, so i try to stay away of those.
<input class="string required form-control" id="foo_foo_attributes_1398082250289_name" name="foo[foo_attributes_attributes][1398082250289][name]" type="text">
on refresh these get set to their index in the ActiveRecord object but it was unclear how to find an element that had been added on the fly – DazBaldwin