Save 36% for Black Friday! Learn more

New Discussion

Notifications

You’re not receiving notifications from this thread.

rails testing always raise the same error

2
Rails

No matter which test file does I run, it always raise this error.
I don't konw how to fix this, thanks!


$rails test test/integration/about_test.rb
Running via Spring preloader in process 5244
Run options: --seed 35591

# Running:

E

Error:
AboutTest#test_can_see_the_about_page:
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_admin_users_on_email"
DETAIL:  Key (email)=() already exists.
: INSERT INTO "admin_users" ("created_at", "updated_at", "id") VALUES ('2017-03-10 07:58:35.156623', '2017-03-10 07:58:35.156623', 298486374)



bin/rails test test/integration/about_test.rb:8



Finished in 0.298578s, 3.3492 runs/s, 0.0000 assertions/s.

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

If you notice the INSERT INTO statement does not include an email which means your tests probably aren't generating random email addresses for the AdminUser objects it's trying to create. You should make sure that those are being generated on your own or with something like factory_girl so that you won't have conflicting user objects in your tests. I'm pretty sure that'll solve your problem once you get that fixed up.

Hey Larry, I had a similar issue so I (quick) fixed it by deleting the

test/fixtures/admin_users.yml

file.

goodluck!

Join the discussion
Create an account Log in