-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
46 lines (37 loc) · 1.22 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
require "rubocop/rake_task"
RuboCop::RakeTask.new
task default: %i[spec rubocop]
namespace :db do
require_relative "./spec/support/test_database"
require "active_record"
require "dotenv/load"
Dotenv.load
desc "Create databases to be used in tests"
task "create" do
adapter = ENV.fetch("ADAPTER", "mysql2")
puts "Creating #{adapter}"
TestDatabase.set_env_database_url(adapter)
TestDatabase.establish_connection
ActiveRecord::Base.connection.create_database(TestDatabase.database_name)
end
desc "Drop databases to be used in tests"
task "drop" do
adapter = ENV.fetch("ADAPTER", "mysql2")
puts "Dropping #{adapter}"
TestDatabase.set_env_database_url(adapter)
TestDatabase.establish_connection
ActiveRecord::Base.connection.drop_database(TestDatabase.database_name)
end
desc "Migrate databases to be used in tests"
task "migrate" do
adapter = ENV.fetch("ADAPTER", "mysql2")
puts "Migrating #{adapter}"
TestDatabase.set_env_database_url(adapter, with_database_name: true)
TestDatabase.establish_connection
TestDatabase.run_migrations
end
end