Sha256: 530ca47a034f3292286b2cae82281f96d59bacb7a367de1d0f960704b40ef60d

Contents?: true

Size: 980 Bytes

Versions: 2

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'mindex'
require 'pry'

require 'sequel'
require 'sqlite3'

DB = Sequel.sqlite('tmp/database.sqlite3')

def reset_configuration!
  Mindex.configure do |config|
    config.elasticsearch_url = ENV.fetch('ELASTICSEARCH_URL', 'localhost:9200')
    config.elasticsearch_user = ENV.fetch('ELASTICSEARCH_USERNAME', 'elastic')
    config.elasticsearch_pass = ENV.fetch('ELASTICSEARCH_PASSWORD', 'changeme')
    config.elasticsearch_options = nil
  end
end

def drop_indices!
  Mindex::Elasticsearch.connect.indices.delete(index: '_all')
end

def drop_sqlite_tables!
  tables = DB[:sqlite_master].where(type: 'table').exclude(name: %w[sqlite_sequence sqlite_master]).select.map { |row| row[:name] }
  tables.each { |table| DB.run("DROP TABLE #{table}") }
end

RSpec.configure do |config|
  config.before(:each) do
    reset_configuration!
    drop_indices!
    drop_sqlite_tables!
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mindex-0.2.0 spec/spec_helper.rb
mindex-0.1.0 spec/spec_helper.rb