[英]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.first
在dev
环境中工作
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请注意以下事项
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.