fix: price_markup with value nil gives exception

fixes #1011
This commit is contained in:
Philipp Rothmann 2023-06-16 13:04:03 +02:00
parent 026c3a6285
commit a1682932ac
2 changed files with 10 additions and 4 deletions

View File

@ -9,7 +9,7 @@ module PriceCalculation
# @return [Number] Price for the foodcoop-member.
def fc_price
add_percent(gross_price, FoodsoftConfig[:price_markup])
add_percent(gross_price, FoodsoftConfig[:price_markup].to_i)
end
private

View File

@ -59,10 +59,16 @@ describe Article do
expect(article.gross_price).to be >= article.price
end
it 'computes the fc price correctly' do
expect(article.fc_price).to eq((article.gross_price * 1.05).round(2))
[[nil, 1],
[0, 1],
[5, 1.05],
[42, 1.42],
[100, 2]].each do |price_markup, percent|
it "computes the fc price with price_markup #{price_markup} correctly" do
FoodsoftConfig.config['price_markup'] = price_markup
expect(article.fc_price).to eq((article.gross_price * percent).round(2))
end
end
it 'knows when it is deleted' do
expect(supplier.deleted?).to be false
supplier.mark_as_deleted