Skip to content

Commit 7da2abe

Browse files
Fix specs to account for trilogy (#88)
1 parent d49c02a commit 7da2abe

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

spec/support/database_helper.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
class DatabaseHelper < DatabaseCleaner::Spec::DatabaseHelper
55
def self.with_all_dbs &block
6-
%w[mysql2 sqlite3 postgres trilogy].map(&:to_sym).each do |db|
6+
all_dbs = %w[mysql2 sqlite3 postgres]
7+
all_dbs << :trilogy if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("7.1.0")
8+
all_dbs.map(&:to_sym).each do |db|
79
yield new(db)
810
end
911
end
@@ -37,7 +39,26 @@ def establish_connection(config = default_config)
3739
end
3840

3941
def load_schema
40-
super
42+
id_column = case db
43+
when :sqlite3
44+
"id INTEGER PRIMARY KEY AUTOINCREMENT"
45+
when :mysql2, :trilogy
46+
"id INTEGER PRIMARY KEY AUTO_INCREMENT"
47+
when :postgres
48+
"id SERIAL PRIMARY KEY"
49+
end
50+
connection.execute <<-SQL
51+
CREATE TABLE IF NOT EXISTS users (
52+
#{id_column},
53+
name INTEGER
54+
);
55+
SQL
56+
57+
connection.execute <<-SQL
58+
CREATE TABLE IF NOT EXISTS agents (
59+
name INTEGER
60+
);
61+
SQL
4162

4263
if db == :postgres
4364
connection.execute <<-SQL

spec/support/sample.config.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ mysql2:
77
port: 3306
88
encoding: utf8
99

10+
trilogy:
11+
adapter: trilogy
12+
database: database_cleaner_test
13+
username: root
14+
password:
15+
host: 127.0.0.1
16+
port: 3306
17+
encoding: utf8
18+
1019
postgres:
1120
adapter: postgresql
1221
database: database_cleaner_test

0 commit comments

Comments
 (0)