1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

do not hold on to a stale connection object. fixes #15998

This commit is contained in:
Aaron Patterson 2014-07-01 17:59:43 -07:00
parent ad778bc422
commit 9d599abe0f
2 changed files with 14 additions and 6 deletions

View file

@ -366,22 +366,27 @@ module ActiveRecord
# This class is used to verify that all migrations have been run before
# loading a web page if config.active_record.migration_error is set to :page_load
class CheckPending
def initialize(app, connection = Base.connection)
def initialize(app)
@app = app
@connection = connection
@last_check = 0
end
def call(env)
if @connection.supports_migrations?
if connection.supports_migrations?
mtime = ActiveRecord::Migrator.last_migration.mtime.to_i
if @last_check < mtime
ActiveRecord::Migration.check_pending!(@connection)
ActiveRecord::Migration.check_pending!(connection)
@last_check = mtime
end
end
@app.call(env)
end
private
def connection
ActiveRecord::Base.connection
end
end
class << self

View file

@ -8,14 +8,17 @@ module ActiveRecord
super
@connection = MiniTest::Mock.new
@app = MiniTest::Mock.new
@pending = CheckPending.new(@app, @connection)
conn = @connection
@pending = Class.new(CheckPending) {
define_method(:connection) { conn }
}.new(@app)
@pending.instance_variable_set :@last_check, -1 # Force checking
end
def teardown
super
assert @connection.verify
assert @app.verify
super
end
def test_errors_if_pending