I am trying to write a test for a form with nested attributes using Cocoon and rails 4. The problem is that I cannot find the form element to set.
I have tried the following commented out variations but get element not found:
click_link('Add Owner') # should display the fields
#fill_in 'First Name', with: "sean"
#find("input#horse_owner_attributes_fname").set('sean')
#find(:xpath, '//input[@id="horse_owner_attributes_lname"]').set("sean")
I am not sure if my problem is the dynamic nature of the cocoon 'link_to_add_association' or just that I do not know how to use find, or some other reason.
My main form is:
#owner
#owner_from_list
= f.collection_select(:owner_id, @owners, :id, :fname, { :prompt => "Existing Owner" }, {:class => 'form-control'} ) # shows drop down of existing records
= link_to_add_association 'Add Owner', f, :owner, :class => "btn btn-default btn-sm", :data => {"association-insertion-method" => "after" } # to add a new record
and my add owner partial:
= f.inputs do
.nested-fields
= f.input :fname, :as => :string, label: "First Name", hint: "Owner's first name REQUIRED", :required => true
= f.input :lname, :as => :string, label: "Last Name", hint: "Last name REQUIRED", :required => true
It looks like a problem I had.
If you want to fill in fields dynamically added after you click on the Cocoon link, you should pass js: true
as an option to the related scenario.
You can see my question and the excellent answer Chris Peters give to me : rspec doesn't see fields dynamically added or removed by cocoon in nested form to have more informations.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句