为电子邮件列添加索引,用于单元测试失败 [英] adding index to email column culprit for unit tests failing

查看:141
本文介绍了为电子邮件列添加索引,用于单元测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的设计和导轨,我只是整合了我的示例应用程序的设计。我注意到,在创建了一个用户模型之后,我的所有单元测试都失败了。我去尝试缩小这一点,发现即使生成的 user_test.rb 的真相也失败:

  ActiveRecord :: RecordNotUnique:SQLite3 :: ConstraintException:\ 
列电子邮件不是唯一的:INSERT INTOusers(...

一旦我评论了 add_index ...

 #add_index:users,:email,:unique => true 

...并重新运行 rake db:test:load 并使用重新运行测试ruby -I test test / unit / user_test.rb it passed。



有没有人体验过?

解决方案

如果你刚刚生成了设计模型,还会产生一个或多或少的这个内容的夹具:

  one:{} 
#column:value

two:{}
#column:value

此灯具尝试创建两个用户,具有相同的(无效)电子邮件。替换为:

  one:
电子邮件:test1@test.com

二:
电子邮件:test2@test.com

它将修复此错误。 >

I am new to devise and rails and I just integrated devise with my sample app. What I noticed is after creating a user model, all my unit tests were failing. I went to try to narrow this and found that even the generated assert 'the truth' one for user_test.rb also fails:

ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: \
    column email is not unique: INSERT INTO "users" (...

Once I commented out the add_index ...

# add_index :users, :email, :unique => true

... and re-ran rake db:test:load and re-run tests with ruby -I test test/unit/user_test.rb it passes.

Has anyone else experience this?

解决方案

If you just generated the devise model, a fixture was also generated with more or less this content:

one: {}
# column: value
#
two: {}
#  column: value

This fixture tries to create two users, with the same (inexistant) email. Replace it by:

one:
  email: test1@test.com

two:
  email: test2@test.com

It will fix this error.

这篇关于为电子邮件列添加索引,用于单元测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆