【发布时间】:2020-01-29 07:36:16
【问题描述】:
我有以下数据库清理策略
DatabaseCleaner.strategy = :truncation, {:except => %w[roles, users, other_tables]}
它仍在清理角色表,我对角色所属的模型没有任何依赖破坏。 这看起来不像预期的行为。 除了 Role 表,数据是持久的。
【问题讨论】:
标签: ruby-on-rails rspec database-cleaner
我有以下数据库清理策略
DatabaseCleaner.strategy = :truncation, {:except => %w[roles, users, other_tables]}
它仍在清理角色表,我对角色所属的模型没有任何依赖破坏。 这看起来不像预期的行为。 除了 Role 表,数据是持久的。
【问题讨论】:
标签: ruby-on-rails rspec database-cleaner
我首先要确保正确定义数组,请在控制台中检查它的计算结果:
> %w[roles, users, other_table]
=> ["roles,", "users,", "other_table"]
(可能)没有名为roles, 的表(末尾有逗号)。
更正为:
DatabaseCleaner.strategy = :truncation, {:except => %w[roles users other_tables]}
因为:
> %w[roles users other_table]
=> ["roles", "users", "other_table"]
【讨论】: