使用带有暂存数据库的 Cucumber,无需截断和事务

发布于 2024-09-28 04:30:37 字数 131 浏览 1 评论 0原文

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

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

是否可以?

We have a Ruby on Rails 2.3.8 project, where data are almost exclusively read only.
We would like to write acceptance tests which use staging database (copy of the production database)

So we do not want to use transactions or truncation of the database tables before or after features and scenarios.

Is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

且行且努力 2024-10-05 04:30:37

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

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

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

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

    def start
    end

    def clean
    end
  end
end

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

My solution was to switch DatabaseCleaner to transaction cleaning strategy in 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

And monkey patch DatabaseCleaner by adding features/support/database_cleaner_patch.rb with

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

    def start
    end

    def clean
    end
  end
end

We have 3 databases in our project, with cross-database queries so we cannot use transactions, otherwise I would not monkey patch DatabaseCleaner

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文