Update variant params in CartController

This commit is contained in:
Matt-Yorkley
2021-01-23 15:45:04 +00:00
parent ec597aab1a
commit 0393ea4219
2 changed files with 4 additions and 3 deletions

View File

@@ -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

View File

@@ -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