1

factory_girl がモデルの url 属性を正しく設定していません。予約語がないか探してみましたが、何も見つかりませんでした。

  factory :attachment do
    association :attachable, factory: :upload

    url "some/path"
    description "Some important file"
  end

私はこの失敗を取得します。知らせurl: nil

1) Attachment should be valid
     Failure/Error: it { should be_valid }
       expected #<Attachment id: 1048, attachable_id: 1047, attachable_type: "Upload", name: nil, url: nil, created_at: nil, updated_at: nil, description: "Some important file"> to be valid, but got errors: Url can't be empty
     # ./spec/models/attachment_spec.rb:14:in `block (2 levels) in <top (required)>'

コンソールで factory_girl を実行したところ、同じ結果が得られましたFactorGirl.attributes_for :attachment

FactoryGirl 4.2.1 で Rails 4 を実行しています。

4

2 に答える 2

1

私はこれと同じ問題を抱えていて、何時間も頭を机にぶつけた後、Spring サーバーを停止して再起動することにしました。それは魔法のように働き始めました。

Spring サーバーを再起動する前に、属性を使用して設定することができましたが、自分のファイルにあったとしても、create :object, new_field: true使用するだけでは機能しませんでした。create :objectnew_field truefactories.rb

于 2014-04-05T17:08:49.137 に答える