Sha256: 464b675414fa59d7b410cc8dc022491a5bbcb884c8bcee7f2f93e6a6e3aac89b

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

require "bundler/gem_tasks"
require "rspec/core/rake_task"

namespace :spec do
  task :db_drop do
    with_connection("template1") { |conn| conn.execute("DROP DATABASE IF EXISTS #{test_database_name}") }
  end

  task :db_create do
    with_connection("template1") { |conn| conn.execute("CREATE DATABASE #{test_database_name}") }
  end

  task :db_load_schema do
    require "active_record"
    with_connection(test_database_name) { load File.join(__dir__, %w{spec schema.rb}) }
  end

  desc "Setup test database"
  task :setup => [:db_drop, :db_create, :db_load_schema]

  def connection_spec
    require 'yaml'
    @connection_spec ||= YAML.load_file(File.join(__dir__, %w(config database.yml)))
  end

  def test_database_name
    connection_spec["test"]["database"]
  end

  def with_connection(database_name)
    require "active_record"
    pool = ActiveRecord::Base.establish_connection(connection_spec["test"].merge("database" => database_name))
    yield ActiveRecord::Base.connection
  ensure
    pool&.disconnect!
  end
end

RSpec::Core::RakeTask.new(:spec)

task :default => :spec

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
inventory_refresh-0.2.3 Rakefile
inventory_refresh-0.2.2 Rakefile
inventory_refresh-0.3.6 Rakefile
inventory_refresh-0.3.5 Rakefile
inventory_refresh-0.3.4 Rakefile
inventory_refresh-0.3.3 Rakefile
inventory_refresh-0.2.1 Rakefile
inventory_refresh-0.3.2 Rakefile
inventory_refresh-0.3.1 Rakefile
inventory_refresh-0.3.0 Rakefile
inventory_refresh-0.2.0 Rakefile
inventory_refresh-0.1.3 Rakefile
inventory_refresh-0.1.2 Rakefile
inventory_refresh-0.1.1 Rakefile