1

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」の動的な性質なのか、それとも単に検索の使い方がわからないのか、その他の理由なのかわかりません。

私の主なフォームは次のとおりです。

#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  
4

1 に答える 1

1

私が抱えていた問題のようです。

js: trueCocoon リンクをクリックした後に動的に追加されたフィールドに入力する場合は、関連するシナリオにオプションとして渡す必要があります。

私の質問と Chris Peters が私に与えてくれた素晴らしい回答を見ることができます: rspec は、より多くの情報を得るためにネストされた形式で cocoon によって動的に追加または削除されたフィールドを認識しません。

于 2014-09-26T23:12:00.347 に答える