diff --git a/app/models/spree/shipping_method_decorator.rb b/app/models/spree/shipping_method_decorator.rb index 44308f4d93..813c947f38 100644 --- a/app/models/spree/shipping_method_decorator.rb +++ b/app/models/spree/shipping_method_decorator.rb @@ -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) diff --git a/spec/models/spree/shipping_method_spec.rb b/spec/models/spree/shipping_method_spec.rb index c345afd683..7bbc506a0f 100644 --- a/spec/models/spree/shipping_method_spec.rb +++ b/spec/models/spree/shipping_method_spec.rb @@ -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