From 720c7d28fd5820135bda24ac1c84fa0577f4a0a2 Mon Sep 17 00:00:00 2001 From: Baptiste DROUET Date: Sat, 3 Aug 2024 11:28:34 +0200 Subject: [PATCH] fix(sale): generate_sales_subscription_offers now returns true --- app/controllers/sales_controller.rb | 5 +++-- app/models/sale.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/sales_controller.rb b/app/controllers/sales_controller.rb index 84b188b..f14a3d7 100644 --- a/app/controllers/sales_controller.rb +++ b/app/controllers/sales_controller.rb @@ -14,8 +14,9 @@ def new def create @sale = @owner.sales_as_client.new(sales_params) - return redirect_to :new_user_sale, user: @user, status: :unprocessable_entity unless - @sale.generate(duration: params[:sale][:duration], seller: current_user) + unless @sale.generate(duration: params[:sale][:duration], seller: current_user) + return redirect_to :new_user_sale, user: @user, status: :unprocessable_entity + end return redirect_to :new_user_sale, user: @user, status: :unprocessable_entity if @sale.empty? authorize! :create, @sale diff --git a/app/models/sale.rb b/app/models/sale.rb index aec2bbe..eeddd7d 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -72,7 +72,7 @@ def generate_sales_subscription_offers(duration) duration -= quantity * offer.duration end end - return if duration.zero? + return true if duration.zero? errors.add(:base, 'Subscription offers are not exhaustive!') false