使用黄瓜与分段数据库,没有截断和事务 [英] Using cucumber with staging database without truncation and transactions

查看:277
本文介绍了使用黄瓜与分段数据库,没有截断和事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个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.

是否有可能?

推荐答案

p>我的解决方案是切换DatabaseCleaner到事务清洗策略在功能/ support / env.rb

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

和猴子补丁DatabaseCleaner通过添加功能/ database_cleaner_patch.rb with

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

我们在我们的项目中有3个数据库,使用跨数据库查询,所以我们不能使用事务,否则我不会修补DatabaseCleaner

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

这篇关于使用黄瓜与分段数据库,没有截断和事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆