From 0393ea4219e16064088ce2dc7e2591b50c336cd8 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:45:04 +0000 Subject: [PATCH] Update variant params in CartController --- app/controllers/cart_controller.rb | 3 ++- spec/controllers/cart_controller_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/cart_controller.rb b/app/controllers/cart_controller.rb index f4ab6abf29..f3a0de59ea 100644 --- a/app/controllers/cart_controller.rb +++ b/app/controllers/cart_controller.rb @@ -50,7 +50,8 @@ class CartController < BaseController def populate_variant_attributes_from_variant(order) params[:variant_attributes].each do |variant_id, attributes| - order.set_variant_attributes(Spree::Variant.find(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 diff --git a/spec/controllers/cart_controller_spec.rb b/spec/controllers/cart_controller_spec.rb index 8605dc8adf..b3f6d46c8f 100644 --- a/spec/controllers/cart_controller_spec.rb +++ b/spec/controllers/cart_controller_spec.rb @@ -110,11 +110,11 @@ 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') + expect(order).to receive(:set_variant_attributes).with(variant, max_quantity: "3") allow(controller).to receive(:current_order).and_return(order) expect do - spree_post :populate, variants: { variant.id => 1 }, variant_attributes: { variant.id => { max_quantity: 3 } } + spree_post :populate, variants: { variant.id => 1 }, variant_attributes: { variant.id => { max_quantity: "3" } } end.to change(Spree::LineItem, :count).by(1) end end