0

我们有一个 Ruby on Rails 2.3.8 项目,其中数据几乎是只读的。我们想编写使用暂存数据库(生产数据库的副本)的验收测试

所以我们不想在功能和场景之前或之后使用事务或截断数据库表。

可能吗?

4

1 回答 1

0

我的解决方案是将 DatabaseCleaner 切换到 features/support/env.rb 中的事务清理策略

if defined?(ActiveRecord::Base)
  begin
    require 'database_cleaner'
    DatabaseCleaner.strategy = :transaction
  rescue LoadError => ignore_if_database_cleaner_not_present
  end
end

猴子补丁 DatabaseCleaner 通过添加 features/support/database_cleaner_patch.rb 与

module DatabaseCleaner::ActiveRecord
  #for now we will disable transactions 
  class Transaction

    def start
    end

    def clean
    end
  end
end

我们的项目中有 3 个数据库,具有跨数据库查询,因此我们不能使用事务,否则我不会修改 DatabaseCleaner

于 2010-11-15T14:48:56.740 回答