Skip to content

Commit

Permalink
Fix specs to account for trilogy (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
petergoldstein authored Oct 20, 2023
1 parent d49c02a commit 7da2abe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
25 changes: 23 additions & 2 deletions spec/support/database_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

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

def load_schema
super
id_column = case db
when :sqlite3
"id INTEGER PRIMARY KEY AUTOINCREMENT"
when :mysql2, :trilogy
"id INTEGER PRIMARY KEY AUTO_INCREMENT"
when :postgres
"id SERIAL PRIMARY KEY"
end
connection.execute <<-SQL
CREATE TABLE IF NOT EXISTS users (
#{id_column},
name INTEGER
);
SQL

connection.execute <<-SQL
CREATE TABLE IF NOT EXISTS agents (
name INTEGER
);
SQL

if db == :postgres
connection.execute <<-SQL
Expand Down
9 changes: 9 additions & 0 deletions spec/support/sample.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ mysql2:
port: 3306
encoding: utf8

trilogy:
adapter: trilogy
database: database_cleaner_test
username: root
password:
host: 127.0.0.1
port: 3306
encoding: utf8

postgres:
adapter: postgresql
database: database_cleaner_test
Expand Down

0 comments on commit 7da2abe

Please sign in to comment.