From a6ed4a2c6aaf20671f622afe9bc7f61cab8aac63 Mon Sep 17 00:00:00 2001 From: Pierre de Lacroix Date: Sat, 29 Apr 2017 06:16:05 +0200 Subject: [PATCH] fix bad return value in method Spree::Adjustment#find_closest_tax_rates_from_included_tax --- app/helpers/checkout_helper.rb | 1 - app/models/spree/adjustment_decorator.rb | 8 ++++---- spec/models/spree/adjustment_spec.rb | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index 193c4cef4d..7397ce812e 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -55,7 +55,6 @@ module CheckoutHelper def display_adjustment_tax_rates(adjustment) tax_rates = adjustment.tax_rates - return "" if adjustment.amount == adjustment.included_tax tax_rates.map { |tr| number_to_percentage(tr.amount * 100, :precision => 1) }.join(", ") end diff --git a/app/models/spree/adjustment_decorator.rb b/app/models/spree/adjustment_decorator.rb index 4ad456ba12..255f3de51a 100644 --- a/app/models/spree/adjustment_decorator.rb +++ b/app/models/spree/adjustment_decorator.rb @@ -47,14 +47,14 @@ module Spree return originator.tax_category ? originator.tax_category.tax_rates.match(source) : [] end else - [find_closest_tax_rate_from_included_tax] + find_closest_tax_rates_from_included_tax end end - def find_closest_tax_rate_from_included_tax + def find_closest_tax_rates_from_included_tax approximation = (included_tax / (amount - included_tax)) - return nil if approximation.infinite? or approximation.zero? - Spree::TaxRate.order("ABS(amount - #{approximation})").first + return [] if approximation.infinite? or approximation.zero? + [Spree::TaxRate.order("ABS(amount - #{approximation})").first] end diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 64113c6290..2292381009 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -288,12 +288,12 @@ module Spree let!(:tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new, amount: 0.25) } let!(:other_tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new, amount: 0.3) } - it "returns nil if there is no included tax" do - adjustment_without_tax.find_closest_tax_rate_from_included_tax.should == nil + it "returns [] if there is no included tax" do + adjustment_without_tax.find_closest_tax_rates_from_included_tax.should == [] end it "returns the most accurate tax rate" do - adjustment_with_tax.find_closest_tax_rate_from_included_tax.should == tax_rate + adjustment_with_tax.find_closest_tax_rates_from_included_tax.should == [tax_rate] end end end