Testing in RSpec failing because of DatabaseCleaner

0

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

  

ActiveRecord :: RecordNotUnique:           SQLite3 :: ConstraintException: UNIQUE constraint failed:

What can it be?

    
asked by anonymous 21.08.2017 / 15:30

1 answer

1

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

In an application that was developing, this configuration solved this problem (I have already experienced this 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.

    
22.08.2017 / 14:22