PG::ConnectionBad(连接关闭),当运行rspec时,从Rails 5.2升级到6.0



我试图将我的应用程序从Rails 5.2升级到6.0,当运行rspec升级后,它会引发PG::ConnectionBad: connection is closed错误。

错误是由rails_helper.rb中的ActiveRecord::Migration.maintain_test_schema!表达式引起的,错误如下,

root@00de976cbbd4:/app# rspec
An error occurred while loading rails_helper.
Failure/Error: ActiveRecord::Migration.maintain_test_schema!
PG::ConnectionBad:
connection is closed
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/postgresql/quoting.rb:21:in `escape_string'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/postgresql/quoting.rb:21:in `quote_string'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/quoting.rb:220:in `_quote'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/postgresql/quoting.rb:144:in `_quote'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/quoting.rb:18:in `quote'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/postgresql/schema_statements.rb:750:in `quoted_scope'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/postgresql/schema_statements.rb:727:in `data_source_sql'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/connection_adapters/abstract/schema_statements.rb:62:in `table_exists?'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/internal_metadata.rb:32:in `table_exists?'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/tasks/database_tasks.rb:347:in `schema_up_to_date?'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/migration.rb:594:in `block in load_schema_if_pending!'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/migration.rb:593:in `all?'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/migration.rb:593:in `load_schema_if_pending!'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/migration.rb:614:in `block in maintain_test_schema!'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/migration.rb:867:in `suppress_messages'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/migration.rb:619:in `method_missing'
# /usr/local/bundle/gems/activerecord-6.0.3.5/lib/active_record/migration.rb:614:in `maintain_test_schema!'
# ./spec/rails_helper.rb:30:in `<top (required)>'
No examples found.
No examples found.

我可以启动RAILS_ENV=test rails c和运行ActiveRecord::Migration.maintain_test_schema!在控制台没有错误。并试图将rspec从3.10.1升级到4-0-dev,但仍然得到同样的错误。提前谢谢。

最后我创建了一个新的rails 6应用程序,然后按文件复制文件以检查导致此错误的原因,事实证明,在我的spec/support文件夹中有一个文件shared_db_conntection.rb,它具有以下内容,这是从这个博客http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/

复制的
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

删除此文件后没有此错误

相关内容

  • 没有找到相关文章

最新更新