mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Fix calculations for weight when variant.unit_value is zero
This commit is contained in:
@@ -54,6 +54,8 @@ module Calculator
|
||||
# Customer ends up getting 350mL (line_item.final_weight_volume) of wine
|
||||
# that represent 2.8 (quantity_implied_in_final_weight_volume) glasses of wine
|
||||
def quantity_implied_in_final_weight_volume(line_item)
|
||||
return line_item.quantity if line_item.variant.unit_value.zero?
|
||||
|
||||
(1.0 * line_item.final_weight_volume / line_item.variant.unit_value).round(3)
|
||||
end
|
||||
|
||||
|
||||
@@ -163,19 +163,11 @@ describe Calculator::Weight do
|
||||
|
||||
before { subject.set_preference(:per_kg, 5) }
|
||||
|
||||
it "returns NaN if variant.weight is not present" do
|
||||
expect(subject.compute(line_item1).nan?).to be_truthy
|
||||
end
|
||||
|
||||
xit "uses zero weight if variant.weight is not present" do
|
||||
it "uses zero weight if variant.weight is not present" do
|
||||
expect(subject.compute(line_item1)).to eq 0
|
||||
end
|
||||
|
||||
it "returns NaN if variant.weight is present" do
|
||||
expect(subject.compute(line_item2).nan?).to be_truthy
|
||||
end
|
||||
|
||||
xit "uses the variant weight if variant.weight is present" do
|
||||
it "uses the variant weight if variant.weight is present" do
|
||||
expect(subject.compute(line_item2)).to eq 50.0
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user