-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
82 lines (70 loc) · 1.71 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
79
80
81
82
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rspec/core/rake_task'
require 'fileutils'
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end
module Postgres
class << self
def exec(query)
`psql postgres -tAc "#{query}"`
end
def user_exists?(username)
exec("SELECT 1 FROM pg_user WHERE usename='#{username}'").strip == '1'
end
def drop_user(username)
puts "dropping user #{username}"
puts exec("DROP USER #{username}").inspect
end
def create_user(username)
user_exists?(username) ? false : `createuser -s #{username}`
end
end
end
def within_dummy_app
Dir.chdir('spec/dummy') do
ENV['BUNDLE_GEMFILE'] = File.join File.dirname(__FILE__), 'Gemfile'
yield
end
end
desc 'Run specs'
RSpec::Core::RakeTask.new(spec: :setup)
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Qbrick'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
desc 'set up the dummy app for testing'
task :setup do
Postgres.create_user 'screenconcept'
within_dummy_app do
`bundle exec rake qbrick:install:migrations`
`bundle exec rails generate qbrick:install:assets`
`bundle exec rake db:drop`
`bundle exec rake db:create`
`bundle exec rake db:migrate`
`bundle exec rake db:test:prepare`
end
end
task default: [:spec]
desc 'start the dummy app'
task :start_dummy do
within_dummy_app do
`bundle exec rails server`
end
end
namespace :dummy_db do
desc 'migrate in dummy app'
task :migrate do
within_dummy_app do
`bundle exec rake db:migrate 2>&1`
end
end
end