Simplify shipping_method.include? method

This commit is contained in:
luisramos0
2019-06-15 22:01:18 +01:00
parent ccc7a43a06
commit 2b3865855d
2 changed files with 18 additions and 2 deletions

View File

@@ -57,8 +57,7 @@ Spree::ShippingMethod.class_eval do
# It allows checkout using shipping methods without zones (see issue #3928 for details)
# and it allows checkout with addresses outside of the zones of the selected shipping method
def include?(address)
return false unless address
true
address.present?
end
def has_distributor?(distributor)

View File

@@ -92,5 +92,22 @@ module Spree
it { expect(shipping_method.delivery?).to be false }
end
end
describe "#include?" do
let(:shipping_method) { create(:shipping_method) }
it "does not include a nil address" do
expect(shipping_method.include?(nil)).to be false
end
it "includes an address that is not included in the zones of the shipping method" do
address = create(:address)
zone_mock = instance_double(Spree::Zone)
allow(zone_mock).to receive(:include?).with(address).and_return(false)
allow(shipping_method).to receive(:zones) { [zone_mock] }
expect(shipping_method.include?(address)).to be true
end
end
end
end