mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add capacity to weight calculator to calculate based on any object with an order (needed in spree 2 to calculate based on package)
This commit is contained in:
@@ -17,7 +17,9 @@ module OpenFoodNetwork
|
||||
private
|
||||
|
||||
def line_items_for(object)
|
||||
if object.respond_to? :line_items
|
||||
if object.respond_to? :order
|
||||
object.order.line_items
|
||||
elsif object.respond_to? :line_items
|
||||
object.line_items
|
||||
elsif object.respond_to?(:variant) && object.respond_to?(:quantity)
|
||||
[object]
|
||||
|
||||
@@ -24,4 +24,18 @@ describe OpenFoodNetwork::Calculator::Weight do
|
||||
subject.set_preference(:per_kg, 10)
|
||||
subject.compute(line_item).should == 10*2 * 10
|
||||
end
|
||||
|
||||
it "computes shipping cost for an object with an order" do
|
||||
variant_1 = double(:variant, :weight => 10)
|
||||
variant_2 = double(:variant, :weight => 5)
|
||||
|
||||
line_item_1 = double(:line_item, :variant => variant_1, :quantity => 1)
|
||||
line_item_2 = double(:line_item, :variant => variant_2, :quantity => 2)
|
||||
|
||||
order = double(:order, :line_items => [line_item_1, line_item_2])
|
||||
object_with_order = double(:object_with_order, order: order)
|
||||
|
||||
subject.set_preference(:per_kg, 10)
|
||||
subject.compute(object_with_order).should == (10*1 + 5*2) * 10
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user