Error in follow-up, PG :: InFailedSqlTransaction from Rspec

I tried to run rspec from the model specification file, but I got this error: "An error occurred while intercepting"

"An error occurred after intercepting PG :: InFailedSqlTransaction: ERROR: current transaction aborts, commands are ignored until the end of the transaction. Occurred in C: / Ruby193 / lib /.../ postgresql_adapter: 294"

I was looking for this problem, and I found a suggestion to lower my "database_cleaner" to "1.0.1". I did, but it will not work. Does anyone know how to solve this? Thanks in advance!

+7
ruby-on-rails gem rspec
source share
1 answer

This can happen if you execute the wrong SQL statement in the transaction scope, you throw an exception from this statement, and then try to execute another SQL statement in the same transaction.

Once one statement in a transaction fails, no more statements can be executed in this transaction.

Here is an example:

ActiveRecord::Base.transaction do begin ActiveRecord::Base.connection.execute "A bad query" rescue => ex puts ex.message end puts User.count end 

User.count calls PG::InFailedSqlTransaction because the previous SQL statement raised ActiveRecord::StatementInvalid and was swallowed by rescue .

So, I would look for code that saves as part of a transaction, and then try to run additional SQL statements.

+13
source share

All Articles