简体   繁体   English

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

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

I have this controller method我有这个控制器方法

def dashboard
 method1
 method2
 method3
 ..
end

Everything is working fine in development environment.. but in test environment, i am getting this error after first few methods.development环境中一切正常......但在test环境中,我在前几种方法后收到此错误。

I checked using binding.pry just above the line which i used to get error,我使用binding.pry在我曾经出错的行上方进行了检查,

I cannot run any query eg: Account.first but same Account.first works in dev environment我无法运行任何查询, eg: Account.first但相同的Account.firstdev环境中工作

Error when i run in test environment: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'

Please note the following请注意以下事项

  • No erros found in other controllers and respective spec.在其他控制器和各自的规范中没有发现错误。
  • There was no error in the same controller from other branch来自其他分支的同一个控制器没有错误
  • I added few code to method1 , which executes just fine in both environment.我在method1添加了一些代码,它在两种环境中都可以正常执行。 i am getting these error after method3 which i havent touched.我收到后,这些错误method3 ,我还没有触及。

PS: I did google and search stackoverflow questions, didnt help PS:我做了谷歌和搜索stackoverflow问题,没有帮助

Edit: When i moved the method1 to end, i am not getting any errors, please explain me this behaviour.编辑:当我提出的method1结束,我没有得到任何错误,请解释我这种行为。

Did you try to reset the Test Database?您是否尝试重置测试数据库?

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

or for Rails Version older than 5或者对于低于 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

or shorter:或更短:

bundle exec rake db:reset RAILS_ENV=test bundle exec rake db:reset RAILS_ENV=test

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ActiveRecord::StatementInvalid: PG InFailedSqlTransaction - ActiveRecord::StatementInvalid: PG InFailedSqlTransaction ActiveRecord :: StatementInvalid:Rails中的PG :: UndefinedColumn - ActiveRecord::StatementInvalid: PG::UndefinedColumn in Rails ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:在Rails查询中 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: in rails query Rails抛出ActiveRecord :: StatementInvalid PG :: NotNullViolation:错误 - Rails throwing ActiveRecord::StatementInvalid PG::NotNullViolation: ERROR Rails 4:使用 RSpec 测试 rake 任务时的 PG::InFailedSqlTransaction - Rails 4: PG::InFailedSqlTransaction when testing a rake task with RSpec ActiveRecord :: StatementInvalid(PG :: UndefinedFunction - ActiveRecord::StatementInvalid (PG::UndefinedFunction Rails/Grape 应用程序中的排序错误 ActiveRecord::StatementInvalid PG::UndefinedColumn - Sorting error ActiveRecord::StatementInvalid PG::UndefinedColumn in Rails/Grape app Rails:使用ActiveRecord :: StatementInvalid失败的测试:PG :: NotNullViolation:错误 - Rails: Failing test with an ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR ActiveRecord :: StatementInvalid:PG :: UndefinedTable:错误:与HABTM与rails关联的关系 - ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation with HABTM association with rails 后挂钩错误,来自Rspec的PG :: InFailedSqlTransaction - Error in an after hook, PG::InFailedSqlTransaction from Rspec
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM