【问题标题】:Database Cleaner strategy is cleaning the table mention in except block of truncation strategy数据库清理器策略正在清理除截断块策略之外的表
【发布时间】:2020-01-29 07:36:16
【问题描述】:

我有以下数据库清理策略

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

它仍在清理角色表,我对角色所属的模型没有任何依赖破坏。 这看起来不像预期的行为。 除了 Role 表,数据是持久的。

【问题讨论】:

    标签: ruby-on-rails rspec database-cleaner


    【解决方案1】:

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

    > %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"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      相关资源
      最近更新 更多