mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Merge pull request #13103 from mkllnk/gmaps-region-code
Simplify default country code lookup
This commit is contained in:
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@@ -67,7 +67,6 @@ jobs:
|
||||
- name: Set up database
|
||||
run: |
|
||||
bin/rails db:create db:schema:load
|
||||
bin/rails runner spec/support/seeds.rb # Asset compile needs a country.
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
@@ -213,7 +212,6 @@ jobs:
|
||||
- name: Set up database
|
||||
run: |
|
||||
bin/rails db:create db:schema:load
|
||||
bin/rails runner spec/support/seeds.rb # Asset compile needs a country.
|
||||
|
||||
- name: Run tests
|
||||
|
||||
@@ -301,7 +299,6 @@ jobs:
|
||||
- name: Set up database
|
||||
run: |
|
||||
bin/rails db:create db:schema:load
|
||||
bin/rails runner spec/support/seeds.rb # Asset compile needs a country.
|
||||
|
||||
- name: Run tests
|
||||
|
||||
@@ -390,7 +387,6 @@ jobs:
|
||||
- name: Set up database
|
||||
run: |
|
||||
bin/rails db:create db:schema:load
|
||||
bin/rails runner spec/support/seeds.rb # Asset compile needs a country.
|
||||
|
||||
- name: Run tests
|
||||
|
||||
@@ -470,7 +466,6 @@ jobs:
|
||||
- name: Set up database
|
||||
run: |
|
||||
bin/rails db:create db:schema:load
|
||||
bin/rails runner spec/support/seeds.rb # Asset compile needs a country.
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
|
||||
@@ -5,15 +5,14 @@ class DefaultCountry
|
||||
country.id
|
||||
end
|
||||
|
||||
# Two letter code defined in ISO-3166-1.
|
||||
def self.code
|
||||
country.iso
|
||||
# Changing ENV requires restarting the process.
|
||||
ENV.fetch("DEFAULT_COUNTRY_CODE", nil)
|
||||
end
|
||||
|
||||
def self.country
|
||||
# Changing ENV requires restarting the process.
|
||||
iso = ENV.fetch("DEFAULT_COUNTRY_CODE", nil)
|
||||
|
||||
# When ENV changes on restart, this cache will be reset as well.
|
||||
@country ||= Spree::Country.find_by(iso:) || Spree::Country.first
|
||||
@country ||= Spree::Country.find_by(iso: code) || Spree::Country.first
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user