20

Recently I had a problem with one of my cucumber scenarios. Certain entries in my test database were disappearing whilst the feature was running. I solved the problem by changing the line

DatabaseCleaner.strategy = :transaction

to

DatabaseCleaner.strategy = :truncation

I'm not sure why that helped. There is a table on the database cleaners gem webpage, but it dosen't really say what the two terms mean. Any help on understanding the difference between the two concepts would be great.

elliance
  • 571
  • 5
  • 14

2 Answers2

41

Putting it in a very simple way: truncation removes all data from the database and transaction rollbacks all changes that has been made by the running scenario.

socjopata
  • 5,028
  • 3
  • 30
  • 33
2

Truncation removes the data leaving the database structure, transaction majorly rollback the database operation and it is the fastest strategy. And there is the last one which is deletion. Deletion deletes the data and removes the structure of the database, it is the slowest but safest. You can also check Difference between truncation, transaction and deletion database strategies

Community
  • 1
  • 1
Olalekan Sogunle
  • 2,299
  • 1
  • 20
  • 26