加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby轨道 – 钢轨工厂女孩得到“电子邮件已经被采取”

发布时间:2020-12-16 19:24:54 所属栏目:百科 来源:网络整理
导读:这是我的工厂女孩??代码,每次我尝试生成评论时,告诉我“电子邮件已经被使用”,我重置了我的数据库,将spec_helper中的转换设置为true,但仍然没有解决问题.我是新来的,我使用的协会错了吗?谢谢! Factory.define :user do |user| user.name "Testing User" us
这是我的工厂女孩??代码,每次我尝试生成评论时,告诉我“电子邮件已经被使用”,我重置了我的数据库,将spec_helper中的转换设置为true,但仍然没有解决问题.我是新来的,我使用的协会错了吗?谢谢!
Factory.define :user do |user|
  user.name                  "Testing User"
  user.email                 "test@example.com"
  user.password              "foobar"
  user.password_confirmation "foobar"
end

Factory.define :course do |course|
  course.title "course"
  course.link "www.umn.edu"
  course.sections 21
  course.description "test course description"
  course.association :user
end

Factory.define :review do |review|
  review.title "Test Review"
  review.content "Test review content"
  review.association :user
  review.association :course
end

解决方法

您需要使用序列来阻止创建具有相同电子邮件的用户对象,因为您必须对用户模型中的电子邮件的唯一性进行验证.
Factory.sequence :email do |n|
  “test#{n}@example.com”
end

Factory.define :user do |user|
  user.name "Testing User"
  user.email { Factory.next(:email) }
  user.password "foobar"
  user.password_confirmation "foobar"
end

您可以在Factory Girl documentation阅读更多.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读