在我们的PostgreSQL支持的Rails项目中,当使用spork运行rspec时,有时我们会收到以下错误:
ActiveRecord::StatementInvalid:
PG::Error: ERROR: prepared statement "a1" already exists最初,它每天只发生几次,但最近,它开始每3-4次测试运行一次,这会使我们的开发工作变得缓慢。
有没有办法在spec_helper.rb文件中的某个地方重置/删除PostgreSQL中的准备好的语句?
发布于 2012-12-14 00:32:31
在搜索了PostgreSQL docs并在spec_helper.rb中的不同位置对其进行了大量的试验和错误测试后,我最终发现可以添加以下代码来删除所有现有的准备好的语句,此后我再也没有看到这个错误:
RSpec.configure do |config|
# ... other code
config.after(:suite) do
ActiveRecord::Base.connection.execute("DEALLOCATE ALL")
end
# ... other code
end发布于 2013-01-11 11:24:21
如果您正在执行以下操作,则可以获得此结果:
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(这是推荐的here)。
如果你有它或类似的东西,试着删除它。
https://stackoverflow.com/questions/13864286
复制相似问题