forked from sivers/store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tools.rb
32 lines (27 loc) · 837 Bytes
/
test_tools.rb
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
# This file is just some common shared things used by tests in subdirectories
require 'pg'
require 'minitest/autorun'
require 'json'
DB = PG::Connection.new(dbname: 'dude_test', user: 'dude', host: 'db')
SCHEMA ||= File.read('schema.sql')
FIXTURES ||= File.read('fixtures.sql')
class Minitest::Test
def setup
DB.exec(P_SCHEMA) if Module::const_defined?('P_SCHEMA')
DB.exec(SCHEMA)
DB.exec(P_FIXTURES) if Module::const_defined?('P_FIXTURES')
DB.exec(FIXTURES)
end
end
Minitest.after_run do
DB.exec(P_SCHEMA) if Module::const_defined?('P_SCHEMA')
DB.exec(SCHEMA)
DB.exec(P_FIXTURES) if Module::const_defined?('P_FIXTURES')
DB.exec(FIXTURES)
end
module JDB
def qry(sql, params=[])
@res = DB.exec_params("SELECT * FROM #{sql}", params)
@j = JSON.parse(@res[0]['js'], symbolize_names: true) if(@res[0]['js'])
end
end