From d99e598e7a7e344280656d27f79ed95766a2fb73 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 10 May 2021 18:37:01 +0100 Subject: [PATCH] Delete dead code in CartController The two conditionals in #populate_variant_attributes here are never actually true, so the subsequent code paths are never reached. --- app/controllers/cart_controller.rb | 24 ------------------------ spec/controllers/cart_controller_spec.rb | 1 - spec/models/spree/order_spec.rb | 5 ----- 3 files changed, 30 deletions(-) diff --git a/app/controllers/cart_controller.rb b/app/controllers/cart_controller.rb index 6e6fb22775..2555ed6f34 100644 --- a/app/controllers/cart_controller.rb +++ b/app/controllers/cart_controller.rb @@ -20,8 +20,6 @@ class CartController < BaseController render json: { error: cart_service.errors.full_messages.join(",") }, status: :precondition_failed end - - populate_variant_attributes end private @@ -40,26 +38,4 @@ class CartController < BaseController authorize! :create, Spree::Order end end - - def populate_variant_attributes - order = current_order.reload - - populate_variant_attributes_from_variant(order) if params.key? :variant_attributes - populate_variant_attributes_from_product(order) if params.key? :quantity - end - - def populate_variant_attributes_from_variant(order) - params[:variant_attributes].each do |variant_id, attributes| - permitted = attributes.permit(:quantity, :max_quantity).to_h.with_indifferent_access - order.set_variant_attributes(Spree::Variant.find(variant_id), permitted) - end - end - - def populate_variant_attributes_from_product(order) - params[:products].each do |_product_id, variant_id| - max_quantity = params[:max_quantity].to_i - order.set_variant_attributes(Spree::Variant.find(variant_id), - max_quantity: max_quantity) - end - end end diff --git a/spec/controllers/cart_controller_spec.rb b/spec/controllers/cart_controller_spec.rb index 5f830c583b..95bbd23927 100644 --- a/spec/controllers/cart_controller_spec.rb +++ b/spec/controllers/cart_controller_spec.rb @@ -110,7 +110,6 @@ describe CartController, type: :controller do order = subject.current_order(true) allow(order).to receive(:distributor) { distributor } allow(order).to receive(:order_cycle) { order_cycle } - expect(order).to receive(:set_variant_attributes).with(variant, max_quantity: "3") allow(controller).to receive(:current_order).and_return(order) expect do diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index e97ac29062..8bfd3c97ec 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -468,11 +468,6 @@ describe Spree::Order do li = Spree::LineItem.last expect(li.max_quantity).to eq(3) end - - it "does nothing when the line item is not found" do - p = build_stubbed(:simple_product) - subject.set_variant_attributes(p.master, { 'max_quantity' => '3' }.with_indifferent_access) - end end describe "applying enterprise fees" do