From b27d5c649225dc4515ecbaf5406ddb507a826e2d Mon Sep 17 00:00:00 2001 From: Fabiano Santos Florentino Date: Mon, 25 Mar 2024 20:15:14 -0300 Subject: [PATCH] Refactor customer deletion logic to use customer.balance.zero? instead of balance? method --- app/use_cases/customer_use_case/delete.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/use_cases/customer_use_case/delete.rb b/app/use_cases/customer_use_case/delete.rb index 6ed92b2..0c99cc0 100644 --- a/app/use_cases/customer_use_case/delete.rb +++ b/app/use_cases/customer_use_case/delete.rb @@ -8,7 +8,7 @@ def initialize(id) end def call - return customer.destroy! if balance? + return customer.destroy! if customer.balance.zero? raise SharedErrors::BalanceEmpty end @@ -18,11 +18,7 @@ def call attr_reader :id def customer - @customer = Customer.includes(:transactions).find(@id) - end - - def balance? - customer.balance.zero? + Customer.includes(:transactions).find(@id) end end end