Skip to content

Commit f9d78f6

Browse files
committed
Test Postgres and add a test matrix on Travis
1 parent 9fba135 commit f9d78f6

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

.travis.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
---
1+
dist: bionic
22
language: ruby
3+
addons:
4+
postgresql: "9.6"
5+
rvm: 2.7.1
36
cache: bundler
4-
rvm:
5-
- 2.7.1
67
before_install: gem install bundler -v 2.1.4
8+
before_script: psql -U postgres -c 'create database sql_spy_test;'
9+
env:
10+
- DATABASE_URL=sqlite3:///tmp/sql_spy_test.sqlite3
11+
- DATABASE_URL=postgres://postgres/sql_spy_test

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ gemspec
55
gem "rake", "~> 12.0"
66
gem "minitest", "~> 5.0"
77
gem "activerecord", "~> 6.0"
8+
gem "pg"
89
gem "sqlite3"
910
gem "byebug"

Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ GEM
2222
i18n (1.8.5)
2323
concurrent-ruby (~> 1.0)
2424
minitest (5.14.2)
25+
pg (1.2.3)
2526
rake (12.3.3)
2627
sqlite3 (1.4.2)
2728
thread_safe (0.3.6)
@@ -36,6 +37,7 @@ DEPENDENCIES
3637
activerecord (~> 6.0)
3738
byebug
3839
minitest (~> 5.0)
40+
pg
3941
rake (~> 12.0)
4042
sql_spy!
4143
sqlite3

test/sql_spy_test.rb

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
require "minitest/autorun"
22
require "active_record"
3+
require "pg"
34
require "sqlite3"
45

56
SQLITE_DATABASE = File.expand_path("../test.sqlite3", __dir__)
67
File.delete(SQLITE_DATABASE) if File.file?(SQLITE_DATABASE)
78

8-
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: SQLITE_DATABASE)
9+
ENV["DATABASE_URL"] ||= "sqlite3://" + SQLITE_DATABASE
10+
ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
11+
912
ActiveRecord::Schema.define do
10-
create_table :users do |t|
11-
t.string :name
13+
unless table_exists?(:users)
14+
create_table :users do |t|
15+
t.string :name
16+
end
1217
end
1318

14-
create_table :posts do |t|
15-
t.references :user
16-
t.string :title
19+
unless table_exists?(:posts)
20+
create_table :posts do |t|
21+
t.references :user
22+
t.string :title
23+
end
1724
end
1825
end
1926

0 commit comments

Comments
 (0)