Rails 7 update - Rspec tests not persisting changes

Very strange one here.

Recently updated app from 6.1 to 7. Previously passing rspec now failing. When binding.pry into the method the record is correctly updated. I.e record.flag is changed from false to true (also when checking the DB the record is correctly updated). However when entering the expect part of the test e.g expect(record.flag).to eq(true) the record has not been changed and even in the DB the changes seem to have not been made.

Would there have been any changes to rspec(or rspec rails) that would cause this? tried looking at changelogs but nothing stood out.

I know this might be hard to diagnose without code but am unable to share as proprietary code.

1 Like

I found the issue, just in case anyone else comes across this:

Rollback transactions when the block returns earlier than expected. That change in ActiveRecord meant that my code which had an early return in a transaction was rolledback.

ActiveRecord::Base.transaction do
 record.update!(flag: true)
 #blah blah
return nil

removing the return nil fixed it

1 Like