Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 testing user initialization is always blank

Hey I have a test that looks like this

test 'create account' do
    if User.create(email: '[email protected]', password: 'blahblah')
        assert true
    else
        assert User.msg
    end
end

But when I try to run it I'm getting an error message like this:

  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)

This looks to me as though I hadn't initialized email, but as I understand this should be initialized with my create above. I'm using strong params so I don't have any attr_accessable enabled and I can run this through. Does anyone know what could be causing this? If you want any more information let me know.

like image 456
Lethjakman Avatar asked Oct 16 '13 22:10

Lethjakman


1 Answers

This was caused by the automatically generated fixtures from the rails scaffolding. For whatever reason this shows up inside of the tests rather than in its own section. When I fixed the fixtures this error stopped appearing.

like image 190
Lethjakman Avatar answered Oct 23 '22 02:10

Lethjakman