ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction

I was getting this error in my tests:

ActiveRecord::StatementInvalid:
  PG::InFailedSqlTransaction:
  ERROR:  current transaction is aborted,
  commands ignored until end of transaction block

Here is my Stack Overflow Answer about it.

It was caused by the fact that each test example was wrapped in a database transaction. The solution is to disable wrapping test examples in database transactions for the examples that cause the problem.