From 389e149ded1f253b09b5e1b4fa739153b968f334 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 3 Feb 2021 11:54:54 +0000 Subject: [PATCH] Wrap updates in a transaction block Ensures the operation will be rolled ack if either saving the new record or deleting the old record fail --- app/services/tax_rate_updater.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/tax_rate_updater.rb b/app/services/tax_rate_updater.rb index 683b76b9ab..d02754640f 100644 --- a/app/services/tax_rate_updater.rb +++ b/app/services/tax_rate_updater.rb @@ -20,7 +20,9 @@ class TaxRateUpdater end def transition_rate! - updated_rate.save && current_rate.destroy + ActiveRecord::Base.transaction do + updated_rate.save && current_rate.destroy + end end private