Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fixed country_iso delegated to country, but country is nil (ActiveSup… (#13863)

Damian Legawiec58081539f094
diff --git a/spree/core/app/models/spree/stock_location.rb b/spree/core/app/models/spree/stock_location.rb
index d8c70aa61c..32855009de 100644
--- a/spree/core/app/models/spree/stock_location.rb
+++ b/spree/core/app/models/spree/stock_location.rb
@@ -27,7 +27,7 @@ module Spree
after_save :ensure_one_default
after_update :conditional_touch_records
- delegate :name, :iso3, :iso, :iso_name, to: :country, prefix: true
+ delegate :name, :iso3, :iso, :iso_name, to: :country, prefix: true, allow_nil: true
def state_text
state.try(:abbr) || state.try(:name) || state_name
diff --git a/spree/core/spec/models/spree/stock_location_spec.rb b/spree/core/spec/models/spree/stock_location_spec.rb
index 55b8715dd7..9634e55295 100644
--- a/spree/core/spec/models/spree/stock_location_spec.rb
+++ b/spree/core/spec/models/spree/stock_location_spec.rb
@@ -344,5 +344,14 @@ module Spree
expect(subject.country_name).to eq(subject.country.name)
end
end
+
+ context 'when country is nil' do
+ subject { build(:stock_location, country: nil, state: nil) }
+
+ it { expect(subject.country_name).to be_nil }
+ it { expect(subject.country_iso).to be_nil }
+ it { expect(subject.country_iso3).to be_nil }
+ it { expect(subject.country_iso_name).to be_nil }
+ end
end
end