Database Cleaner 策略正在清理 table 中提及的截断策略块

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

我有以下数据库清理策略

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

仍在清理角色table并且我没有任何依赖销毁角色所属的模型。 这看起来不像预期的行为。 除了角色 table,数据跨

是持久的。

我首先要确保正确定义数组,请在控制台中检查它的计算结果:

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

(可能)没有 table 称为 roles,(末尾有逗号)。

更正为:

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

因为:

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