diff --git a/spec/dfe/analytics/transaction_changes_spec.rb b/spec/dfe/analytics/transaction_changes_spec.rb index aa195852..8b13a1d5 100644 --- a/spec/dfe/analytics/transaction_changes_spec.rb +++ b/spec/dfe/analytics/transaction_changes_spec.rb @@ -58,5 +58,26 @@ def store_transaction_changes_for_tests expect(entity.stored_transaction_changes).to eq({ 'email_address' => ['foo@bar', 'bar@baz'] }) end end + + context 'with transaction rollback' do + it 'create tracks changes to attributes' do + ActiveRecord::Base.transaction do + @entity = Candidate.create(email_address: 'foo@bar') + raise ActiveRecord::Rollback + end + + expect(@entity.stored_transaction_changes).to be_nil + end + + it 'update tracks changes to attributes' do + entity = Candidate.create(email_address: 'foo@bar') + ActiveRecord::Base.transaction do + entity.update(email_address: 'bar@baz') + raise ActiveRecord::Rollback + end + + expect(entity.stored_transaction_changes).to eq({ 'email_address' => [nil, 'foo@bar'], 'id' => [nil, 1] }) + end + end end end