Skip to content

Instantly share code, notes, and snippets.

@victorhazbunanuff
Created June 28, 2013 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorhazbunanuff/5885872 to your computer and use it in GitHub Desktop.
Save victorhazbunanuff/5885872 to your computer and use it in GitHub Desktop.
refactor
def delayed_deletion
begin
Account.transaction do
update_column(:deleted_at, Date.current)
destroy_subscription
end
rescue Exception; end;
AccountAlertMailer.deletion_notification(admin).deliver
end
context "transaction" do
it "should rollback if exception found in update_column" do
@account.stubs(:update_column).raises(Exception)
@account.delayed_deletion
@account.deleted_at.should be_nil
end
it "should rollback if exception found in destroy_subscription" do
@account.stubs(:destroy_subscription).raises(Exception)
@account.delayed_deletion
@account.reload.deleted_at.should be_nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment