ruby database_cleaner.rb

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby database_cleaner.rb相关的知识,希望对你有一定的参考价值。

RSpec.configure do |config|
  INDEXED_MODELS = [BankAccount, Mandate, Transaction]

  config.around(:each, search: true) do |example|
    WebMock.disable_net_connect!(allow: ENV['ELASTICSEARCH_URL'] || 'localhost:9200')
    INDEXED_MODELS.each { |klass| klass.__elasticsearch__.create_index! }
    example.run
    INDEXED_MODELS.each { |klass| klass.__elasticsearch__.delete_index! }
    WebMock.disable_net_connect!
  end
end
# spec/support/database_cleaner.rb
#
# Set sane default for database cleaner and add a meta tag to enable database commits.
# This is important if you need to test after_commit callbacks in rails. (i.e. elasticsearch)
#
require 'database_cleaner'

RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.clean_with(:truncation)
  end

  config.around(:each) do |example|
    DatabaseCleaner.strategy = example.metadata[:commit] ? :truncation : :transaction
    DatabaseCleaner.cleaning do
      example.run
    end
  end
end

以上是关于ruby database_cleaner.rb的主要内容,如果未能解决你的问题,请参考以下文章

ruby [Ruby Cheat] Cheatsheet #ruby

Ruby运算符

Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速

如何学习ruby?Ruby学习技巧分享

ruby Ruby脚本,看看是否用openssl编译了ruby

什么是ruby?