Fix calculations for weight when variant.unit_value is zero

This commit is contained in:
Matt-Yorkley
2020-03-24 13:51:47 +01:00
parent 87ee4bbebc
commit ef0fb18fda
2 changed files with 4 additions and 10 deletions

View File

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

View File

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