我正在尝试使用 Cocoon 和 rails 4 为具有嵌套属性的表单编写测试。问题是我找不到要设置的表单元素。
我尝试了以下注释掉的变体,但找不到元素:
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")
我不确定我的问题是茧 'link_to_add_association' 的动态特性,还是我不知道如何使用 find 或其他原因。
我的主要形式是:
#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
和我的添加所有者部分:
= 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