Using cucumber with staging database without trunc

2019-09-06 07:27发布

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条回答
淡お忘
2楼-- · 2019-09-06 08:32

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

查看更多
登录 后发表回答