mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7b3813fbe |
@@ -41,7 +41,7 @@ class Api::VariantSerializer < ActiveModel::Serializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unit_price_price
|
def unit_price_price
|
||||||
price_with_fees / unit_price.denominator
|
price_with_fees / (unit_price.denominator || 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unit_price_unit
|
def unit_price_unit
|
||||||
|
|||||||
@@ -25,4 +25,22 @@ describe Api::VariantSerializer do
|
|||||||
:tag_list # Used to apply tag rules
|
:tag_list # Used to apply tag rules
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#unit_price_price" do
|
||||||
|
context "without fees" do
|
||||||
|
it "displays the price divided by the unit price denominator" do
|
||||||
|
allow(subject).to receive_message_chain(:unit_price, :denominator) { 1000 }
|
||||||
|
|
||||||
|
expect(subject.unit_price_price).to eq(variant.price / 1000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the denominator returns nil" do
|
||||||
|
it "returns the price" do
|
||||||
|
allow(subject).to receive_message_chain(:unit_price, :denominator) { nil }
|
||||||
|
|
||||||
|
expect(subject.unit_price_price).to eq(variant.price)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user