Sha256: 4e8ab50a91d62b2c428f49f175ca2fc16e5ce294c02ca803ea1e0baacbe398f2

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "replidog"
require "database_rewinder"
require "pry"

ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../dummy/config/environment", __FILE__)
require "rspec/rails"

RSpec.configure do |config|
  copy_master_to_slave = proc do |adapter|
    case adapter
    when :mysql2
      3.times do |i|
        system("mysql -u root -e 'drop database dummy_test_slave#{i + 1}' > /dev/null 2> /dev/null")
        system("mysql -u root -e 'create database dummy_test_slave#{i + 1}'")
        system("mysqldump -u root dummy_test | mysql -u root dummy_test_slave#{i + 1}")
      end
      system("mysql -u root -e 'drop database dummy_test_user' > /dev/null 2> /dev/null")
      system("mysql -u root -e 'drop database dummy_test_user_slave' > /dev/null 2> /dev/null")
      system("mysql -u root -e 'create database dummy_test_user'")
      system("mysql -u root -e 'create database dummy_test_user_slave'")
      system("mysqldump -u root dummy_test | mysql -u root dummy_test_user")
      system("mysqldump -u root dummy_test | mysql -u root dummy_test_user_slave")
    when :sqlite3
      3.times do |i|
        FileUtils.copy("#{Rails.root}/db/test.sqlite3", "#{Rails.root}/db/test_slave#{i + 1}.sqlite3")
      end
      FileUtils.copy("#{Rails.root}/db/test.sqlite3", "#{Rails.root}/db/test_user.sqlite3")
      FileUtils.copy("#{Rails.root}/db/test.sqlite3", "#{Rails.root}/db/test_user_slave.sqlite3")
    end
  end

  config.run_all_when_everything_filtered = true
  config.filter_run :focus

  config.before(:suite) do
    DatabaseRewinder["test"]
    DatabaseRewinder["test_slave1"]
    DatabaseRewinder["test_slave2"]
    DatabaseRewinder["test_slave3"]
    DatabaseRewinder["test_user"]
    DatabaseRewinder["test_user_slave"]
    DatabaseRewinder.clean_all
    copy_master_to_slave.call(:mysql2)
  end

  config.after(:each) do
    DatabaseRewinder.clean
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
replidog-1.1.0 spec/spec_helper.rb
replidog-1.0.0 spec/spec_helper.rb