簡體   English   中英

Rails Rspec - ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction:

[英]Rails Rspec - ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction:

我有這個控制器方法

def dashboard
 method1
 method2
 method3
 ..
end

development環境中一切正常......但在test環境中,我在前幾種方法后收到此錯誤。

我使用binding.pry在我曾經出錯的行上方進行了檢查,

我無法運行任何查詢, eg: Account.first但相同的Account.firstdev環境中工作

test環境中運行時出錯:

ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR:  current transaction is aborted, commands ignored until end of transaction block
: SELECT  "accounts".* FROM "accounts"  ORDER BY "accounts"."id" ASC LIMIT 1
from /home/qwinix/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:596:in `async_exec'

請注意以下事項

  • 在其他控制器和各自的規范中沒有發現錯誤。
  • 來自其他分支的同一個控制器沒有錯誤
  • 我在method1添加了一些代碼,它在兩種環境中都可以正常執行。 我收到后,這些錯誤method3 ,我還沒有觸及。

PS:我做了谷歌和搜索stackoverflow問題,沒有幫助

編輯:當我提出的method1結束,我沒有得到任何錯誤,請解釋我這種行為。

您是否嘗試重置測試數據庫?

bundle exec rails db:drop RAILS_ENV=test
bundle exec rails db:create RAILS_ENV=test
bundle exec rails db:schema:load RAILS_ENV=test

或者對於低於 5 的 Rails 版本

bundle exec rake db:drop RAILS_ENV=test
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:schema:load RAILS_ENV=test

或更短:

bundle exec rake db:reset RAILS_ENV=test

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM