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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Remove default_country_id configuration
Rafal Cymerys1d0c92717c3a
diff --git a/core/app/models/spree/address.rb b/core/app/models/spree/address.rbindex d473587edf..f9b053e770 100644--- a/core/app/models/spree/address.rb+++ b/core/app/models/spree/address.rb@@ -68,25 +68,6 @@ module Spreeself.whitelisted_ransackable_attributes = ADDRESS_FIELDSself.whitelisted_ransackable_associations = %w[country state user]- def self.build_default- Spree::Deprecation.warn(<<-DEPRECATION, caller)- `Address#build_default` is deprecated and will be removed in Spree 5.0.- Please use standard rails `Address.new(country: current_store.default_country)`- DEPRECATION- new(country: Spree::Country.default)- end-- def self.default(user = nil, kind = 'bill')- Spree::Deprecation.warn(<<-DEPRECATION, caller)- `Address#default` is deprecated and will be removed in Spree 5.0.- DEPRECATION- if user && user_address = user.public_send(:"#{kind}_address")- user_address.clone- else- build_default- end- end-def self.required_fieldsSpree::Address.validators.map do |v|v.is_a?(ActiveModel::Validations::PresenceValidator) ? v.attributes : []diff --git a/core/app/models/spree/country.rb b/core/app/models/spree/country.rbindex 59ed9ea80d..198f41d8bb 100644--- a/core/app/models/spree/country.rb+++ b/core/app/models/spree/country.rb@@ -1,9 +1,5 @@module Spreeclass Country < Spree::Base- # we need to have this callback before any dependent: :destroy associations- # https://github.com/rails/rails/issues/3458- # before_destroy :ensure_not_default-has_many :addresses, dependent: :restrict_with_errorhas_many :states,-> { order name: :asc },@@ -18,17 +14,6 @@ module Spreevalidates :name, :iso_name, :iso, :iso3, presence: true, uniqueness: { case_sensitive: false, scope: spree_base_uniqueness_scope }- def self.default(store = nil)- Spree::Deprecation.warn(<<-DEPRECATION, caller)- `Country#default` is deprecated and will be removed in Spree 5.0.- Please use `current_store.default_country` instead- DEPRECATION- store ||= Spree::Store.default- country_id = store.default_country_id- default = find_by(id: country_id) if country_id.present?- default || find_by(iso: 'US') || first- end-def self.by_iso(iso)where(['LOWER(iso) = ?', iso.downcase]).or(where(['LOWER(iso3) = ?', iso.downcase])).takeend@@ -45,16 +30,5 @@ module Spreedef to_snameend-- private-- def ensure_not_default- Spree::Deprecation.warn('Country#ensure_not_default is deprecated and will be removed in Spree v5')-- if id.eql?(Spree::Config[:default_country_id])- errors.add(:base, Spree.t(:default_country_cannot_be_deleted))- throw(:abort)- end- endendenddiff --git a/core/app/services/spree/seeds/stores.rb b/core/app/services/spree/seeds/stores.rbindex ca932fa793..934c12fb40 100644--- a/core/app/services/spree/seeds/stores.rb+++ b/core/app/services/spree/seeds/stores.rb@@ -7,7 +7,7 @@ module Spreedefault_store = Spree::Store.defaultif default_store.persisted?- default_store.update!(default_country_id: Spree::Config[:default_country_id])+ default_store.update!(default_country: Spree::Country.first)elseSpree::Store.new do |s|s.name = 'Spree Demo Site'@@ -16,7 +16,7 @@ module Sprees.mail_from_address = '[email protected]'s.customer_support_email = '[email protected]'s.default_currency = 'USD'- s.default_country_id = Spree::Config[:default_country_id]+ s.default_country = Spree::Country.firsts.default_locale = I18n.locales.seo_title = 'Spree Commerce Demo Shop's.meta_description = 'This is the new Spree UX DEMO | OVERVIEW: http://bit.ly/new-spree-ux | DOCS: http://bit.ly/spree-ux-customization-docs | CONTACT: https://spreecommerce.org/contact/'diff --git a/core/lib/spree/core/configuration.rb b/core/lib/spree/core/configuration.rbindex f66a6e171a..f59ab05a3a 100644--- a/core/lib/spree/core/configuration.rb+++ b/core/lib/spree/core/configuration.rb@@ -36,7 +36,6 @@ module Spreepreference :company, :boolean, default: false # Request company field for billing and shipping addrpreference :currency, :string, default: 'USD', deprecated: truepreference :credit_to_new_allocation, :boolean, default: false- preference :default_country_id, :integer, deprecated: truepreference :disable_sku_validation, :boolean, default: false # when turned off disables the built-in SKU uniqueness validationpreference :disable_store_presence_validation, :boolean, default: false # when turned off disables Store presence validation for Products and Payment Methodspreference :expedited_exchanges, :boolean, default: false # NOTE this requires payment profiles to be supported on your gateway of choice as well as a delayed job handler to be configured with activejob. kicks off an exchange shipment upon return authorization save. charge customer if they do not return items within timely manner.diff --git a/core/spec/models/spree/address_spec.rb b/core/spec/models/spree/address_spec.rbindex 6071d6a19f..9e3387cb69 100644--- a/core/spec/models/spree/address_spec.rb+++ b/core/spec/models/spree/address_spec.rb@@ -260,45 +260,6 @@ describe Spree::Address, type: :model doendend- xcontext '.default' do- context 'no user given' do- before do- @default_country_id = Spree::Config[:default_country_id]- new_country = create(:country)- Spree::Config[:default_country_id] = new_country.id- end-- after do- Spree::Config[:default_country_id] = @default_country_id- end-- it 'sets up a new record with Spree::Config[:default_country_id]' do- expect(Spree::Address.default.country).to eq(Spree::Country.find(Spree::Config[:default_country_id]))- end-- # Regression test for #1142- it 'uses the first available country if :default_country_id is set to an invalid value' do- Spree::Config[:default_country_id] = '0'- expect(Spree::Address.default.country).to eq(Spree::Country.first)- end- end-- context 'user given' do- let(:bill_address) { Spree::Address.new(phone: Time.current.to_i) }- let(:ship_address) { double('ShipAddress') }- let(:user) { double('User', bill_address: bill_address, ship_address: ship_address) }-- it 'returns a copy of that user bill address' do- expect(Spree::Address.default(user).phone).to eq bill_address.phone- end-- it 'falls back to build default when user has no address' do- allow(user).to receive_messages(bill_address: nil)- expect(Spree::Address.default(user)).to eq Spree::Address.build_default- end- end- end-context '#full_name' docontext 'both first and last names are present' dolet(:address) { create(:address, firstname: 'Michael', lastname: 'Jackson') }@@ -470,12 +431,6 @@ describe Spree::Address, type: :model doendend- describe '.build_default' do- let(:_address) { described_class.build_default }-- it { expect(_address.country).to eq(Spree::Country.default) }- end-context 'editable & destroy' dosubject(:destroy_address) { address.destroy }diff --git a/core/spec/models/spree/country_spec.rb b/core/spec/models/spree/country_spec.rbindex f83d3fb601..2428d54b0b 100644--- a/core/spec/models/spree/country_spec.rb+++ b/core/spec/models/spree/country_spec.rb@@ -30,72 +30,6 @@ describe Spree::Country, type: :model doendend- xdescribe '.default' do- context 'when default_country_id config is set' do- before { Spree::Config[:default_country_id] = canada.id }-- it 'will return the country from the config' do- expect(described_class.default.id).to eql canada.id- end- end-- context 'config is not set though record for america exists' do- before { america.touch }-- it 'will return the US' do- expect(described_class.default.id).to eql america.id- end- end-- context 'when config is not set and america is not created' do- before { canada.touch }-- it 'will return the first record' do- expect(described_class.default.id).to eql canada.id- end- end- end-- xdescribe 'ensure proper country deletion' do- context 'when deleting default country' do- before { Spree::Config[:default_country_id] = america.id }-- it 'does not destroy country' do- expect(america.destroy).to be_falsy- end-- it 'sets correct error message' do- america.destroy-- expect(america.errors[:base]).to include(Spree.t(:default_country_cannot_be_deleted))- end- end-- context 'when deleting not a default country' do- context 'when country has no dependent addresses' do- it 'destroys country successfully' do- expect(canada.destroy).to be_truthy- end- end-- context 'when country has dependent addresses' do- before do- create(:ship_address, country: canada, zipcode: 'l3l 4p4')- end-- it 'does not destroy country' do- expect(canada.destroy).to be_falsy- end-- it 'sets correct error message' do- canada.destroy-- expect(canada.errors[:base]).to include('Cannot delete record because dependent addresses exist')- end- end- end- end-describe '#default?' dobefore doallow_any_instance_of(Spree::Store).to receive(:default).and_return(store)diff --git a/emails/spec/spec_helper.rb b/emails/spec/spec_helper.rbindex a60d6f93a0..23b8b1a125 100644--- a/emails/spec/spec_helper.rb+++ b/emails/spec/spec_helper.rb@@ -63,9 +63,8 @@ RSpec.configure do |config|reset_spree_preferencescountry = create(:country, name: 'United States of America', iso_name: 'UNITED STATES', iso: 'US', states_required: true)- Spree::Config[:default_country_id] = country.id- create(:store, default: true)+ create(:store, default_country: country, default: true)endconfig.include FactoryBot::Syntax::Methods