Rails 4 user initialization check is always empty

Hi, I have a test similar to this

test 'create account' do if User.create(email: ' me@test.com ', password: 'blahblah') assert true else assert User.msg end end 

But when I try to start it, I get an error message:

  1) Error: UserTest#test_create_account: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_users_on_email" DETAIL: Key (email)=() already exists. : INSERT INTO "users" ("created_at", "updated_at", "id") VALUES ('2013-10-16 21:59:54', '2013-10-16 21:59:54', 298486374) 

It looks like I did not initialize the email, but as I understand it, it should be initialized with my created above. I use strong options, so I don't have attr_accessable, and I can run this. Does anyone know what could be causing this? If you need more information, let me know.

+6
source share
2 answers

This was caused by automatically generated scaffolding fixtures. For some reason, this appears inside the tests, and not in its own section. When I fixed the lights, this error stopped appearing.

+8
source

If you get an error message with a unique PostgreSQL message error, your primary key index may not be synchronized, for example. after filling in the database.

Use ActiveRecord::Base.connection.reset_pk_sequence!('users') to re-add the primary key index for the user table.

0
source

Source: https://habr.com/ru/post/956123/


All Articles