From 494b572c69456e7c0cfc73c38aa2ddc99d4d46d4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 31 Jul 2014 15:36:13 +1000 Subject: [PATCH] Do not show zero fees --- lib/open_food_network/enterprise_fee_calculator.rb | 2 +- .../lib/open_food_network/enterprise_fee_calculator_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/open_food_network/enterprise_fee_calculator.rb b/lib/open_food_network/enterprise_fee_calculator.rb index 2d76d8d280..c8070f2ab2 100644 --- a/lib/open_food_network/enterprise_fee_calculator.rb +++ b/lib/open_food_network/enterprise_fee_calculator.rb @@ -19,7 +19,7 @@ module OpenFoodNetwork fees[applicator.enterprise_fee.fee_type.to_sym] ||= 0 fees[applicator.enterprise_fee.fee_type.to_sym] += calculate_fee_for variant, applicator fees - end + end.select { |fee_type, amount| amount > 0 } end diff --git a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb index 21c4848fda..0ca7da4999 100644 --- a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb +++ b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb @@ -45,6 +45,12 @@ module OpenFoodNetwork it "returns a breakdown of fees" do EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product.master).should == {admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12} end + + it "filters out zero fees" do + ef_admin.calculator.update_attribute :preferred_amount, 0 + + EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product.master).should == {sales: 4.56, packing: 7.89, transport: 0.12} + end end describe "creating adjustments" do