将索引添加到电子邮件列导致单元测试失败的罪魁祸首

将索引添加到电子邮件列导致单元测试失败的罪魁祸首

本文介绍了将索引添加到电子邮件列导致单元测试失败的罪魁祸首的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 devise 和 rails 的新手,我刚刚将 devise 与我的示例应用程序集成在一起.我注意到在创建一个 user 模型后,我所有的单元测试都失败了.我尝试缩小范围,发现即使为 user_test.rb 生成的断言真相"也失败了:

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" (...

一旦我注释掉了 add_index ...

Once I commented out the add_index ...

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

... 并重新运行 rake db:test:load 并使用 ruby -I test test/unit/user_test.rb 重新运行测试它通过了.

... 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: [email protected]

two:
  email: [email protected]

它将修复此错误.

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

07-24 13:27