Sha256: f735a2717a5095a38ca9632add54af3661c4d1da7df0387f47a3c1bce653ac5e

Contents?: true

Size: 923 Bytes

Versions: 10

Compression:

Stored size: 923 Bytes

Contents

require 'active_record'

module TurntableHelper
  def reload_turntable!(config_file_name = nil)
    ActiveRecord::Base.send(:include, ActiveRecord::Turntable)
    ActiveRecord::Base.turntable_config_file = config_file_name
    ActiveRecord::Turntable::Config.load!(ActiveRecord::Base.turntable_config_file, :test)
  end

  def establish_connection_to(env = :test)
    silence_warnings {
      Object.const_set('RAILS_ENV', env.to_s)
      Object.const_set('Rails', Object.new)
      allow(Rails).to receive(:env) { ActiveSupport::StringInquirer.new(RAILS_ENV) }
      ActiveRecord::Base.logger = Logger.new("/dev/null")
    }
    ActiveRecord::Base.establish_connection(env)
  end

  def truncate_shard
    ActiveRecord::Base.descendants.each do |klass|
      next if klass.abstract_class?
      klass.delete_all
    end
  end

  def migrate(version)
    ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT, version)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
activerecord-turntable-2.5.0 spec/support/turntable_helper.rb
activerecord-turntable-2.4.0 spec/support/turntable_helper.rb
activerecord-turntable-2.3.3 spec/support/turntable_helper.rb
activerecord-turntable-2.3.2 spec/support/turntable_helper.rb
activerecord-turntable-2.3.1 spec/support/turntable_helper.rb
activerecord-turntable-2.3.0 spec/support/turntable_helper.rb
activerecord-turntable-2.2.2 spec/support/turntable_helper.rb
activerecord-turntable-2.2.1 spec/support/turntable_helper.rb
activerecord-turntable-2.2.0 spec/support/turntable_helper.rb
activerecord-turntable-2.1.1 spec/support/turntable_helper.rb