FactoryGirl specs and duplicate emails

If you’re using FactoryGirl for testing your Rails app and keep getting errors about duplicate entries, emails in my case, first install the database_cleaner gem

database_cleaner

And in your spec_helper.rb file add the following code to your config block:

 config.before(:suite) do
   DatabaseCleaner[:active_record].strategy = :transaction
   DatabaseCleaner.clean_with(:truncation)
 end

 config.before(:each) do
   DatabaseCleaner.start
 end

 config.after(:each) do
   DatabaseCleaner.clean
 end
Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like

Hnggg

I’ve just spent so long on Capistrano deployment and I just found my problem. I’m going to go…

Reconnecting ZNC

So I’ve recently set up ZNC so I can always lurk on Freenode nerds. It’s been working for…