Sha256: e409918fecb232369aa4e41ebcfa25478e96b9a15909e858e9ef9cb9ccedc20e

Contents?: true

Size: 1.72 KB

Versions: 31

Compression:

Stored size: 1.72 KB

Contents

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

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

task :default => :spec

task :setup do
  %w(lib spec).each do |path|
    $LOAD_PATH.unshift(File.expand_path("../#{path}", __FILE__))
  end
  require "database"
  exit if config["database"] == ":memory:"
end

namespace :db do
  desc "Create the database"
  task create: :setup do
    commands = {
      "mysql"    => "mysql -u #{config['username']} -e 'create database #{config["database"]} default character set #{config["encoding"]} default collate #{config["collation"]};' >/dev/null",
      "postgres" => "psql -c 'create database #{config['database']};' -U #{config['username']} >/dev/null"
    }
    %x{#{commands[driver] || true}}
    $?.success? ? puts("Database successfully created.") : puts("There was an error creating the database.")
  end

  desc "Drop the database"
  task drop: :setup do
    commands = {
      "mysql"    => "mysql -u #{config['username']} -e 'drop database #{config["database"]};' >/dev/null",
      "postgres" => "psql -c 'drop database #{config['database']};' -U #{config['username']} >/dev/null"
    }
    %x{#{commands[driver] || true}}
    $?.success? ? puts("Database successfully dropped.") : puts("There was an error dropping the database.")
  end

  desc "Set up the database schema"
  task up: :setup do
    orm = ENV['ORM']
    return unless orm

    require orm
    require "database"
    require "#{orm}/schema"
    DB = Mobility::Test::Database.connect(orm)
    Mobility::Test::Schema.up
  end

  desc "Drop and recreate the database schema"
  task :reset => [:drop, :create]

  def config
    Mobility::Test::Database.config[driver]
  end

  def driver
    Mobility::Test::Database.driver
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
mobility-0.8.11 Rakefile
mobility-0.8.10 Rakefile
mobility-0.8.9 Rakefile
mobility-0.8.8 Rakefile
mobility-0.8.7 Rakefile
mobility-0.8.6 Rakefile
mobility-0.8.5 Rakefile
mobility-0.8.4 Rakefile
mobility-0.8.3 Rakefile
mobility-0.8.2 Rakefile
mobility-0.8.1 Rakefile
mobility-0.8.0 Rakefile
mobility-0.7.6 Rakefile
mobility-0.7.5 Rakefile
mobility-0.7.4 Rakefile
mobility-0.7.3 Rakefile
mobility-0.7.2 Rakefile
mobility-0.7.1 Rakefile
mobility-0.7.0 Rakefile
mobility-0.6.0 Rakefile