唯一约束失败: users.email: 插入到"users" ( "created_at" , "updated_at" , "id" ) 值 ()



这是我的static_pages_controller_test,

    require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest
  test "should get home" do
    get static_pages_home_url
    assert_response :success
  end
  test "should get help" do
    get static_pages_help_url
    assert_response :success
  end
  test "should get about" do
    get static_pages_about_url
    assert_response :success
  end
end

错误:

StaticPagesControllerTest#test_should_get_home: ActiveRecord::RecordNotUnique: SQLite3::ConstraintException: UNIQUE 约束失败: users.email:插入到"用户"("created_at", "updated_at"、"id"( 值 ('2018-01-17 05:49:27.300065', '2018-01-17 05:49:27.300065', 298486374(

我已经将User.yml更改为,

one:
email: test1@test.com
two:
email: test2@test.com

错误:

StaticPagesControllerTest#test_should_get_about: 活动记录::Fixture::FormatError: fixture key 不是哈希: C:/Sites/IntenetChatSystem/test/fixtures/users.yml, keys: ["one", "电子邮件",我是两个"]

我感到困惑我该怎么办,pplz给出一些建议

必须修复user.yml文件的缩进:

one:
  email: test1@test.com
two:
  email: test2@test.com

错误消息本身就是一个很好的提示,"夹具键不是哈希:......键:"一","电子邮件",我是两个"]"您可以在键列表中看到存在oneemail键。相反,您应该拥有的只是onetwo键。

最新更新