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。