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.

Use bang methods in seeds to avoid silently failing (#11347)

Damian Legawiecbd7241d5b562
diff --git a/core/app/services/spree/seeds/countries.rb b/core/app/services/spree/seeds/countries.rb
index 14a12c96a9..360ffea618 100644
--- a/core/app/services/spree/seeds/countries.rb
+++ b/core/app/services/spree/seeds/countries.rb
@@ -19,7 +19,7 @@ module Spree
iso: country.alpha_2_code,
iso_name: country.name.upcase,
numcode: country.numeric_code
- ).first_or_create
+ ).first_or_create!
end
# Find countries that do not use postal codes (by iso) and set 'zipcode_required' to false for them.
diff --git a/core/app/services/spree/seeds/roles.rb b/core/app/services/spree/seeds/roles.rb
index cff1c50d93..723cbad0a5 100644
--- a/core/app/services/spree/seeds/roles.rb
+++ b/core/app/services/spree/seeds/roles.rb
@@ -6,8 +6,8 @@ module Spree
EXCLUDED_COUNTRIES = ['AQ', 'AX', 'GS', 'UM', 'HM', 'IO', 'EH', 'BV', 'TF'].freeze
def call
- Spree::Role.where(name: 'admin').first_or_create
- Spree::Role.where(name: 'user').first_or_create
+ Spree::Role.where(name: 'admin').first_or_create!
+ Spree::Role.where(name: 'user').first_or_create!
end
end
end
diff --git a/core/app/services/spree/seeds/states.rb b/core/app/services/spree/seeds/states.rb
index 9a77542408..097acc4e1b 100644
--- a/core/app/services/spree/seeds/states.rb
+++ b/core/app/services/spree/seeds/states.rb
@@ -45,7 +45,7 @@ module Spree
country.states.where(
name: subregion.name,
abbr: subregion.code
- ).first_or_create
+ ).first_or_create!
end
def province_level(country, subregion)
@@ -53,7 +53,7 @@ module Spree
country.states.where(
name: province.name,
abbr: province.code
- ).first_or_create
+ ).first_or_create!
end
end
end