Ask A Question

Notifications

You’re not receiving notifications from this thread.

rails testing always raise the same error

Larry Qu asked in 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
Reply

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.

Reply

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

test/fixtures/admin_users.yml

file.

goodluck!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.