diff --git a/spec/support/database_helper.rb b/spec/support/database_helper.rb index 4808edb9..4f11a224 100644 --- a/spec/support/database_helper.rb +++ b/spec/support/database_helper.rb @@ -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 @@ -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 diff --git a/spec/support/sample.config.yml b/spec/support/sample.config.yml index 7b0761ff..4ca69247 100644 --- a/spec/support/sample.config.yml +++ b/spec/support/sample.config.yml @@ -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