创建(:用户)时,FactoryGirl电子邮件已存在

时间:2015-10-21 22:39:01

标签: ruby-on-rails rspec factory-bot

我在测试中使用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

0 个答案:

没有答案