Rails not rolling back transaction after failed save()

后端 未结 2 1619
刺人心
刺人心 2021-01-13 19:18

I have this domain model: A user has group of items, and the state of the items can fail a validation.

Validation works fine, and I even see exceptions get called wh

2条回答
  •  Happy的楠姐
    2021-01-13 19:33

    It sounds like you're hitting a nested transaction problem in your tests.

    I don't believe the Ruby driver for Postgres handles nested transactions, so you only get the scope of the outer transaction. If you have transactional fixtures enabled, there's an outer transaction wrapping your test execution. This means if your controller under test creates a second, inner transaction, and attempts to roll it back - you may not get the right behavior.

    You can confirm the transaction interference by turning off the transactions in rspec:

    RSpec.configure do |config|
      config.use_transactional_fixtures = false
    end
    

提交回复
热议问题