require "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) task :default => :spec # defines an environment task so we can run rake tasks from lib/tasks/rails-sharding.rake. # They require the :environment task, which is defined by rails, but we don need anything task :environment do # do nothing end namespace :db do namespace :test do desc 'Loads gem test environment and rake tasks from gem' task :load_env do require 'rspec' # requires spec helper but ensures no test coverage is reported to codeclimate ENV['CODECLIMATE_REPO_TOKEN'] = nil require './spec/spec_helper' load 'lib/tasks/rails-sharding.rake' end desc "Creates database shards for testing the gem" task create: [:load_env] do # simply calls shards:create as it will work properly after spec_helper # changed the shards configuration Rake::Task['shards:create'].invoke end desc "Drops database shards for testing the gem" task drop: [:load_env] do Rake::Task['shards:drop'].invoke end desc "Migrates database shards for testing the gem" task migrate: [:load_env] do Rake::Task['shards:migrate'].invoke end desc "Prepares database shards for testing the gem (this will clear and recreate database)" task prepare: [:load_env] do Rake::Task['db:test:drop'].invoke Rake::Task['db:test:create'].invoke Rake::Task['db:test:migrate'].invoke end end end