Rspec test failing because of Databasecleaner

Asked

Viewed 43 times

0

I was having trouble with tests about 4 days ago. At first, I had trouble with "database is locked" and in the file where the DatabaseCleaner is configured; changed two lines they used :transaction for :truncation and solved the problem. However, another:

Activerecord::Recordnotunique: Sqlite3::Constraintexception: UNIQUE Constraint failed:

What can it be?

1 answer

1

Probably the test database is not being cleaned up, causing this problem which basically says that the record is not unique.

In an application I was developing, this configuration solved this problem (I have already gone through this same problem).

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

config.before(:each) do
  DatabaseCleaner.strategy = :truncation
  DatabaseCleaner.clean
end

config.after(:each) do
  DatabaseCleaner.clean
end

Give me feedback on my answer.

  • I will test this code today and give you feedback. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.