mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user