forked from bradrobertson/apartment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
78 lines (60 loc) · 1.85 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require 'bundler' rescue 'You must `gem install bundler` and `bundle install` to run rake tasks'
Bundler.setup
Bundler::GemHelper.install_tasks
require "rspec"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = "spec/**/*_spec.rb"
end
namespace :spec do
[:tasks, :unit, :adapters, :integration].each do |type|
RSpec::Core::RakeTask.new(type) do |spec|
spec.pattern = "spec/#{type}/**/*_spec.rb"
end
end
namespace :unit do
RSpec::Core::RakeTask.new(:adapters) do |spec|
spec.pattern = "spec/unit/adapters/**/*_spec.rb"
end
end
end
task :default => :spec
namespace :postgres do
require 'active_record'
require "#{File.join(File.dirname(__FILE__), 'spec', 'support', 'config')}"
desc 'Build the PostgreSQL test databases'
task :build_db do
%x{ createdb -E UTF8 #{pg_config['database']} } rescue "test db already exists"
ActiveRecord::Base.establish_connection pg_config
load 'spec/dummy/db/schema.rb'
end
desc "drop the PostgreSQL test database"
task :drop_db do
puts "dropping database #{pg_config['database']}"
%x{ dropdb #{pg_config['database']} }
end
end
namespace :mysql do
require 'active_record'
require "#{File.join(File.dirname(__FILE__), 'spec', 'support', 'config')}"
desc 'Build the MySQL test databases'
task :build_db do
%x{ mysqladmin -u root create #{my_config['database']} } rescue "test db already exists"
ActiveRecord::Base.establish_connection my_config
load 'spec/dummy/db/schema.rb'
end
desc "drop the MySQL test database"
task :drop_db do
puts "dropping database #{my_config['database']}"
%x{ mysqladmin -u root drop #{my_config['database']} }
end
end
def config
Apartment::Test.config['connections']
end
def pg_config
config['postgresql']
end
def my_config
config['mysql']
end