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阅读更多. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- oracle高级函数
- 页面flash对象的使用
- React学习实例总结,包含yeoman安装、webpack构建
- react 日常遇坑
- c# – 如何阻止linqpad显示写入Debug.Writeline的语句输出?
- ruby – 是否可以让class.property = x返回x以外的东西?
- 将SQLite与经典ASP一起使用
- objective-c – 如何实现或模拟“抽象”OCUnit测试类?
- c# – BackgroundWorker RunWorkerCompletedEventArgs.Canc
- ruby-on-rails-3 – Rails select_tag – 设置include_blan