Skip to content

Commit

Permalink
test rollbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
goodviber committed Jan 9, 2025
1 parent fc854f3 commit 7dc0af8
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/dfe/analytics/transaction_changes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7dc0af8

Please sign in to comment.