mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-09 03:20:21 +00:00
Update variant params in CartController
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user