mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
remove setters from DefaultCountry service
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user