forked from alassek/activerecord-pg_enum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
45 lines (35 loc) · 1.19 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
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "appraisal"
require "pry"
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
task :default => :appraisal
else
task :default => :spec
end
task :connection do
require "active_record"
require_relative "spec/support/connection_config"
config = db_config_hash.except(:database)
if ActiveRecord.constants.include?(:DatabaseConfigurations)
config = ActiveRecord::DatabaseConfigurations::HashConfig.new("test", "primary", config)
end
ActiveRecord::Base.establish_connection(config)
end
namespace :spec do
RSpec::Core::RakeTask.new(:run)
desc "Setup the Database for testing"
task setup: [:connection] do
ActiveRecord::Base.connection_pool.with_connection do |conn|
conn.create_database ENV.fetch("TEST_DATABASE", "pg_enum_test"), owner: ENV.fetch("TEST_USER") { ENV.fetch("USER", "pg_enum") }
end
end
desc "Discard the test database"
task teardown: [:connection] do
ActiveRecord::Base.connection_pool.with_connection do |conn|
conn.drop_database ENV.fetch("TEST_DATABASE", "pg_enum_test")
end
end
task reset: [:teardown, :setup]
end
task spec: %w[spec:setup spec:run spec:teardown]