Sha256: 65ff6600a072e7f54cce31ed101d5c1d00f91971dfe089d2815b69c34a901784

Contents?: true

Size: 887 Bytes

Versions: 13

Compression:

Stored size: 887 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|
      klass.delete_all
    end
  end

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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
activerecord-turntable-2.1.0 spec/support/turntable_helper.rb
activerecord-turntable-2.1.0.rc2 spec/support/turntable_helper.rb
activerecord-turntable-2.1.0.rc1 spec/support/turntable_helper.rb
activerecord-turntable-2.1.0.beta2 spec/support/turntable_helper.rb
activerecord-turntable-2.1.0.beta1 spec/support/turntable_helper.rb
activerecord-turntable-2.0.6 spec/support/turntable_helper.rb
activerecord-turntable-2.0.5 spec/support/turntable_helper.rb
activerecord-turntable-2.0.4 spec/support/turntable_helper.rb
activerecord-turntable-2.0.3 spec/support/turntable_helper.rb
activerecord-turntable-2.0.2 spec/support/turntable_helper.rb
activerecord-turntable-2.0.1 spec/support/turntable_helper.rb
activerecord-turntable-2.0.0 spec/support/turntable_helper.rb
activerecord-turntable-2.0.0.rc1 spec/support/turntable_helper.rb