7709: Merge branch 'master' into 7709-api-rails4
[arvados.git] / services / api / Rakefile
1 #!/usr/bin/env rake
2 # Add your own tasks in files placed in lib/tasks ending in .rake,
3 # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
5 require File.expand_path('../config/application', __FILE__)
6
7 Server::Application.load_tasks
8
9 namespace :test do
10   task(:run).clear
11   # Copied from the definition in Rails 3.2.
12   # This may need to be updated if we upgrade Rails.
13   task :run do
14     errors = %w(test:units test:functionals test:integration test:tasks).collect do |task|
15       begin
16         Rake::Task[task].invoke
17         nil
18       rescue => e
19         { :task => task, :exception => e }
20       end
21     end.compact
22
23     if errors.any?
24       puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n")
25       abort
26     end
27   end
28 end
29
30 namespace :db do
31   namespace :structure do
32     task :dump do
33       require 'tempfile'
34       origfnm = File.expand_path('../db/structure.sql', __FILE__)
35       tmpfnm = Tempfile.new 'structure.sql', File.expand_path('..', origfnm)
36       begin
37         tmpfile = File.new tmpfnm, 'w'
38         origfile = File.new origfnm
39         origfile.each_line do |line|
40           if /^SET lock_timeout = 0;/ =~ line
41             # Avoid edit wars between versions that do/don't write this line.
42             next
43           elsif /^COMMENT ON EXTENSION/ =~ line
44             # Avoid warning message when loading:
45             # "structure.sql:22: ERROR:  must be owner of extension plpgsql"
46             tmpfile.write "-- "
47           end
48           tmpfile.write line
49         end
50         origfile.close
51         tmpfile.close
52         File.rename tmpfnm, origfnm
53         tmpfnm = false
54       ensure
55         File.unlink tmpfnm if tmpfnm
56       end
57     end
58   end
59 end
60
61 # Work around Rails3+PostgreSQL9.5 incompatibility (pg_dump used to
62 # accept -i as a no-op, but now it's not accepted at all).
63 module Kernel
64   alias_method :orig_backtick, :`
65   def `(*args) #`#` sorry, parsers
66     args[0].sub!(/\Apg_dump -i /, 'pg_dump ') rescue nil
67     orig_backtick(*args)
68   end
69 end