Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails unit testing failing due to Devise admin user

I have a simple unit test:

def test_conversation_without_a_name_is_invalid
    conversation = Conversation.new
    assert conversation.name.blank?
    assert !conversation.valid?
end

that is failing with:

1) Error: test_conversation_without_a_name_is_invalid(ConversationTest): ActiveRecord::RecordNotUnique: PG::Error: ERROR: duplicate key value violates unique constraint "index_admins_on_email" DETAIL: Key (email)=() already exists.

It seems that for some reason the test is trying to create a Devise admin user and failing, but I have no idea why it is trying to do this in the first place, or even how to correct it.

I ran the same test in the rails console and it worked fine, very confused.

Has anyone run into this before or know what is going on? Any help would be appreciated!

like image 402
Mark Kadlec Avatar asked Oct 30 '25 22:10

Mark Kadlec


1 Answers

Tracked it down to a fixtures:all statement in my test_helper.rb, still learning my way in Rails, but thanks to Alfonso for the great suggetions.

like image 118
Mark Kadlec Avatar answered Nov 01 '25 14:11

Mark Kadlec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!