diff --git a/app/services/default_country.rb b/app/services/default_country.rb index 7c753cd569..c805e261b0 100644 --- a/app/services/default_country.rb +++ b/app/services/default_country.rb @@ -1,22 +1,13 @@ class DefaultCountry def self.id - DefaultCountry.country.id + country.id end def self.code - DefaultCountry.country.iso + country.iso end def self.country Spree::Country.find_by(iso: ENV["DEFAULT_COUNTRY_CODE"]) || Spree::Country.first end - - def self.id=(id) - ENV["DEFAULT_COUNTRY_CODE"] = Spree::Country.find(id).iso - end - - def self.code=(code) - country = Spree::Country.find_by(iso: code) || Spree::Country.first - ENV["DEFAULT_COUNTRY_CODE"] = country.iso - end end diff --git a/spec/features/admin/configuration/states_spec.rb b/spec/features/admin/configuration/states_spec.rb index fc8d025fcd..10e87ceb88 100755 --- a/spec/features/admin/configuration/states_spec.rb +++ b/spec/features/admin/configuration/states_spec.rb @@ -10,8 +10,10 @@ describe "States" do before(:each) do login_as_admin - @hungary = Spree::Country.create!(name: "Hungary", iso_name: "Hungary") - DefaultCountry.code = country.iso + @hungary = Spree::Country.create!(name: "Hungary", iso_name: "Hungary", iso: "HU") + + allow(ENV).to receive(:[]).and_call_original + allow(ENV).to receive(:[]).with("DEFAULT_COUNTRY_CODE").and_return("HU") end # TODO: For whatever reason, rendering of the states page takes a non-trivial amount of time diff --git a/spec/models/spree/address_spec.rb b/spec/models/spree/address_spec.rb index f57f04d25e..f334392657 100644 --- a/spec/models/spree/address_spec.rb +++ b/spec/models/spree/address_spec.rb @@ -144,23 +144,21 @@ describe Spree::Address do end context ".default" do - before do - @default_country_id = DefaultCountry.id - new_country = create(:country) - DefaultCountry.code = new_country.iso - end - - after do - DefaultCountry.id = @default_country_id - end it "sets up a new record the default country" do expect(Spree::Address.default.country).to eq DefaultCountry.country end # Regression test for #1142 - it "uses the first available country if :default_country_id is set to an invalid value" do - DefaultCountry.code = "notacountry" - expect(Spree::Address.default.country).to eq Spree::Country.first + + context "The default country code is set to an invalid value" do + before do + allow(ENV).to receive(:[]).and_call_original + allow(ENV).to receive(:[]).with("DEFAULT_COUNTRY_CODE").and_return("notacountry") + end + + it "uses the first available country" do + expect(Spree::Address.default.country).to eq Spree::Country.first + end end end