我在rails应用程序中启动了测试环境,当我使用默认代码测试用户模型时,它会抛出以下错误: 测试代码: test "the truth" do assert trueend1) Error:UserTest#test_the_truth:ActiveRecord::RecordNotUnique: Mysq
测试代码:
test "the truth" do assert true end 1) Error: UserTest#test_the_truth: ActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry '' for key 'index_users_on_email': INSERT INTO `users` (`created_at`, `updated_at`, `id`) VALUES ('2014-02-01 17:45:51', '2014-02-01 17:45:51', 298486374)
在我的用户模型中,我有以下关联
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable validates :user_name , :email, :first_name ,:last_name , :presence => true has_many :invitations has_many :incoming_friends, -> { where(:status => '1') }, :class_name => "User", :foreign_key => "friend_id", :through => :invitations has_many :outgoing_friends, -> { where(:status => '1') }, :class_name => "User", :foreign_key => "user_id", :through => :invitations首先,检查test / fixtures / users.yml中的用户模型夹具.如果您有一个和两个的空声明:
one: {} # column: value # two: {} # column: value
它可能会导致问题,因为缺乏属性.删除此部分或评论它:
#one: {} # column: value # #two: {} # column: value
然后尝试再次运行它.