Skip to content

Commit 951bdb6

Browse files
committed
Postgres, fix rake tasks tests
1 parent 8b89f63 commit 951bdb6

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

test/db/postgresql/rake_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def do_teardown
5656
ActiveRecord.schema_format = :sql
5757
# Rake::Task["db:create"].invoke
5858
create_rake_test_database do |connection|
59-
create_schema_migrations_table(connection)
59+
create_schema_migrations_table
6060
connection.create_table('users') { |t| t.string :name; t.timestamps }
6161
end
6262

@@ -113,6 +113,9 @@ def psql(args)
113113
if username = ENV['PSQL_USERNAME']
114114
args = "--username=#{username} #{args}"
115115
end
116+
117+
puts "psql args: #{args}"
118+
116119
`#{PSQL_EXE} #{args}`
117120
end
118121

test/rake_test_support.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ def new_application
121121

122122
# (Test) Helpers :
123123

124-
def create_schema_migrations_table(connection = ActiveRecord::Base.connection)
125-
schema_migration = connection.schema_migration
124+
def create_schema_migrations_table
125+
pool = ActiveRecord::Base.connection_pool
126+
schema_migration = pool.schema_migration
126127

127128
return if schema_migration.table_exists?
128129

@@ -133,26 +134,26 @@ def create_schema_migrations_table(connection = ActiveRecord::Base.connection)
133134

134135
def create_rake_test_database
135136
ActiveRecord::Base.establish_connection db_config
136-
connection = ActiveRecord::Base.connection
137+
connection = ActiveRecord::Base.lease_connection
137138
connection.create_database(db_name, db_config) if connection.respond_to?(:create_database)
138139
if block_given?
139140
if db_name
140141
config = db_config.merge :database => db_name
141142
ActiveRecord::Base.establish_connection config
142143
end
143-
yield ActiveRecord::Base.connection
144+
yield ActiveRecord::Base.lease_connection
144145
end
145-
ActiveRecord::Base.connection.disconnect!
146+
ActiveRecord::Base.lease_connection.disconnect!
146147
end
147148

148149
def drop_rake_test_database(silence = false)
149150
ActiveRecord::Base.establish_connection db_config
150151
begin
151-
ActiveRecord::Base.connection.drop_database(db_name)
152+
ActiveRecord::Base.lease_connection.drop_database(db_name)
152153
rescue => e
153154
raise e unless silence
154155
end
155-
ActiveRecord::Base.connection.disconnect!
156+
ActiveRecord::Base.lease_connection.disconnect!
156157
end
157158

158159
def structure_sql_filename

0 commit comments

Comments
 (0)