Database Cleaner strategy is cleaning the table mention in except block of truncation strategy

202 Views Asked by At

I have the following database cleaner strategy

DatabaseCleaner.strategy = :truncation, {:except => %w[roles, users, other_tables]} 

It's still cleaning the roles table and I don't have any dependent destroy on the models that role belongs to. This does not look like intended behavior. Other than Role table, data is persistent across.

1

There are 1 best solutions below

0
Greg On BEST ANSWER

I'd first make sure to define the array correctly, please check in the console what it evaluates to:

> %w[roles, users, other_table]
=> ["roles,", "users,", "other_table"]

There's (probably) no table called roles, (with a comma at the end).

Correct that to:

DatabaseCleaner.strategy = :truncation, {:except => %w[roles users other_tables]}

because:

> %w[roles users other_table]
=> ["roles", "users", "other_table"]