From 42d65fdac014b4cfe390a4ea57bf5c1fd19d6dd3 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 3 Dec 2024 11:05:59 +0100 Subject: [PATCH 1/2] Fix(promotions): Validate benefits on save On Slack, we got a report that the tiered percent calculator wasn't converting its tiers to BigDecimal when being first created. Since this conversion happens `before_validation`, we should not turn validation off in this controller. Specs still run through. --- .../backend/solidus_promotions/admin/benefits_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb b/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb index cd0f40da056..10a24ef10b4 100644 --- a/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb +++ b/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb @@ -14,7 +14,7 @@ def new def create @benefit = @benefit_type.new(benefit_params) @benefit.promotion = @promotion - if @benefit.save(validate: false) + if @benefit.save flash[:success] = t("spree.successfully_created", resource: SolidusPromotions::Benefit.model_name.human) redirect_to location_after_save, format: :html From d98ec79d4e1a433459aa6f5a1d64a6657635dc95 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 3 Dec 2024 17:38:23 +0100 Subject: [PATCH 2/2] Add status code to benefits controller action These should help Turbo interpret what's going on. --- .../backend/solidus_promotions/admin/benefits_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb b/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb index 10a24ef10b4..354a37ac8ba 100644 --- a/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb +++ b/promotions/lib/controllers/backend/solidus_promotions/admin/benefits_controller.rb @@ -19,7 +19,7 @@ def create t("spree.successfully_created", resource: SolidusPromotions::Benefit.model_name.human) redirect_to location_after_save, format: :html else - render :new, layout: false + render :new, layout: false, status: :unprocessable_entity end end @@ -28,7 +28,7 @@ def edit if params.dig(:benefit, :calculator_type) @benefit.calculator_type = params[:benefit][:calculator_type] end - render layout: false + render layout: false, status: :unprocessable_entity end def update @@ -39,7 +39,7 @@ def update t("spree.successfully_updated", resource: SolidusPromotions::Benefit.model_name.human) redirect_to location_after_save, format: :html else - render :edit + render :edit, status: :unprocessable_entity end end