2,763
社区成员
发帖
与我相关
我的任务
分享
class User
include Mongoid::Document
field name, type: String
validates :name, uniquess: true
end
class Post
include Mongoid::Document
belongs_to :user
end
FactoryGirl.define do
factory :user do #这会创建user
name 'user'
end
end
FactoryGirl.define do
factory :post1, class: 'Post' do
user #这会创建user
end
end
FactoryGirl.define do
factory :post2, class: 'Post' do
user #这会创建user
end
end
Mongoid::default_client.database.drop
FactoryGirl.lint
rake aborted!
FactoryGirl::InvalidFactoryError: The following factories are invalid:
* user -
message:
Validation of User failed.
summary:
The following errors were found: Name is already taken
resolution:
Try persisting the document with valid data or remove the validations. (Mongoid::Errors::Validations)/home/hello/workspace/scaffold/vendor/bundle/ruby/2.1.0/gems/factory_girl-4.5.0/lib/factory_girl/linter.rb:14:in `lint!'
。。。