Using cucumber with staging database without truncation and transactions

不打扰是莪最后的温柔 提交于 2020-01-17 06:58:32

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/3980427/using-cucumber-with-staging-database-without-truncation-and-transactions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!