我在测试中使用FactoryGirl,但是当我执行@user = create(:user)时,我得到了
ActiveRecord::RecordInvalid: Validation failed: Email has already been taken
我已经在我的工厂设置了这样的序列
FactoryGirl.define do
sequence :email do |n|
"email#{n}#{rand(200).to_s}#{rand(200).to_s}@factory.com"
end
factory :user do
email
password 'password'
password_confirmation 'password'
customer_id nil
staff
end
end