I have several tests that need a FactoryGirl factory to be created. So now I have create :review in several RSpec tests. However, when I run the entire test suite I get the following error:
Failure/Error: create :review
ActiveRecord::RecordInvalid:
Validation failed: Slug has already been taken
What is the best way to create :review so it is available to multiple tests? Or should I be doing it differently within each test?
If your app is set up correctly, the data should be cleared between each test provided set_transactional_fixtures is true, so this should only be a problem if you need to create more than one review within a single test. Is that the case?
I do not have set_transactional_fixtures set any where that I can see. Where should that be set? And no, I only need to create one review for each test.
So I checked test.log and saw the restaurant was being created twice for one of my tests. I removed the create :restaurant statement and it worked. However, I am not sure why. Shouldn’t the restaurant still need to be created?