File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ def self.with_all_dbs &block
1111 def setup
1212 Kernel . const_set "User" , Class . new ( ActiveRecord ::Base )
1313 Kernel . const_set "Agent" , Class . new ( ActiveRecord ::Base )
14+ Kernel . const_set "UserProfile" , Class . new ( ActiveRecord ::Base ) if db == :postgres
1415
1516 super
1617
@@ -25,6 +26,7 @@ def teardown
2526
2627 Kernel . send :remove_const , "User" if defined? ( User )
2728 Kernel . send :remove_const , "Agent" if defined? ( Agent )
29+ Kernel . send :remove_const , "UserProfile" if defined? ( UserProfile )
2830 end
2931
3032 private
@@ -33,4 +35,25 @@ def establish_connection(config = default_config)
3335 ActiveRecord ::Base . establish_connection ( config )
3436 @connection = ActiveRecord ::Base . connection
3537 end
38+
39+ def load_schema
40+ super
41+
42+ if db == :postgres
43+ connection . execute <<-SQL
44+ CREATE TABLE IF NOT EXISTS user_profiles (
45+ user_id INTEGER,
46+ FOREIGN KEY(user_id) REFERENCES users(id)
47+ );
48+ SQL
49+ end
50+ end
51+
52+ def drop_db
53+ if db == :postgres
54+ connection . execute "DROP TABLE IF EXISTS user_profiles"
55+ end
56+
57+ super
58+ end
3659end
You can’t perform that action at this time.
0 commit comments