File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44class 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
Original file line number Diff line number Diff line change 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+
1019postgres :
1120 adapter : postgresql
1221 database : database_cleaner_test
You can’t perform that action at this time.
0 commit comments