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.

Added per-store seeding for newly created stores (#14690)

Damian Legawiec9b76c9dacada
diff --git a/spree/core/app/services/spree/seeds/all.rb b/spree/core/app/services/spree/seeds/all.rb
index 96c9c38276..47cf21021d 100644
--- a/spree/core/app/services/spree/seeds/all.rb
+++ b/spree/core/app/services/spree/seeds/all.rb
@@ -10,39 +10,14 @@ module Spree
# countries gem, and zones are migration-only, so none of them
# are seeded.
- # additional data
- TaxCategories.call
-
- # store & channels
Stores.call
- Channels.call
- # Roles are store-owned, so they can only be seeded once a store
- # exists — every store gets its own immutable admin role.
- Roles.call
- # Store-scoped, so it can only run once a store exists.
- DigitalDelivery.call
+ Spree::Store.find_each { |store| StoreResources.call(store: store) }
# The warehouse, delivery zones and pickup are not seeded: their
# shape depends on which country the shop sells from, and nobody
# has answered that yet. Spree::Stores::ProvisionDefaults builds
# them from the merchant's answer — at first-run setup, or here
# when ADMIN_EMAIL/ADMIN_PASSWORD name an install that skips it.
AdminUser.call
-
- # add store resources
- PaymentMethods.call
- TaxCategories.call
- ProductTypes.call
- CustomerGroups.call
- ReturnsEnvironment.call
- # The marketplace's catch-all rate, at the bottom of the list so
- # narrower rates added later resolve ahead of it.
- CommissionRates.call
- # What a new seller has to do before this marketplace will let
- # them trade. Runs after stores for the same reason roles do.
- SellerRequirements.call
- ApiKeys.call
- SavedReports.call
- AllowedOrigins.call
end
end
end
diff --git a/spree/core/app/services/spree/seeds/allowed_origins.rb b/spree/core/app/services/spree/seeds/allowed_origins.rb
index d9b7b60ee9..491ff57f92 100644
--- a/spree/core/app/services/spree/seeds/allowed_origins.rb
+++ b/spree/core/app/services/spree/seeds/allowed_origins.rb
@@ -2,11 +2,12 @@ module Spree
module Seeds
class AllowedOrigins
prepend Spree::ServiceModule::Base
+ include StoreScoped
- def call
- Spree::Store.all.each do |store|
- store.allowed_origins.find_or_create_by!(origin: 'http://localhost')
- end
+ private
+
+ def seed(store)
+ store.allowed_origins.find_or_create_by!(origin: 'http://localhost')
end
end
end
diff --git a/spree/core/app/services/spree/seeds/api_keys.rb b/spree/core/app/services/spree/seeds/api_keys.rb
index da6ad2f259..badd92039b 100644
--- a/spree/core/app/services/spree/seeds/api_keys.rb
+++ b/spree/core/app/services/spree/seeds/api_keys.rb
@@ -2,17 +2,18 @@ module Spree
module Seeds
class ApiKeys
prepend Spree::ServiceModule::Base
+ include StoreScoped
- def call
- Spree::Store.find_each do |store|
- unless store.api_keys.active.publishable.where(channel_id: nil).exists?
- store.api_keys.create!(name: 'Default', key_type: 'publishable')
- end
+ private
- wholesale = store.channels.find_by(code: Channels::WHOLESALE_CODE)
- if wholesale && !store.api_keys.active.publishable.where(channel: wholesale).exists?
- store.api_keys.create!(name: 'Storefront (Wholesale)', key_type: 'publishable', channel: wholesale)
- end
+ def seed(store)
+ unless store.api_keys.active.publishable.where(channel_id: nil).exists?
+ store.api_keys.create!(name: 'Default', key_type: 'publishable')
+ end
+
+ wholesale = store.channels.find_by(code: Channels::WHOLESALE_CODE)
+ if wholesale && !store.api_keys.active.publishable.where(channel: wholesale).exists?
+ store.api_keys.create!(name: 'Storefront (Wholesale)', key_type: 'publishable', channel: wholesale)
end
end
end
diff --git a/spree/core/app/services/spree/seeds/channels.rb b/spree/core/app/services/spree/seeds/channels.rb
index 61e313e6f9..3e7ef03499 100644
--- a/spree/core/app/services/spree/seeds/channels.rb
+++ b/spree/core/app/services/spree/seeds/channels.rb
@@ -6,18 +6,19 @@ module Spree
# See docs/plans/5.6-store-channel-context-and-key-binding.md.
class Channels
prepend Spree::ServiceModule::Base
+ include StoreScoped
WHOLESALE_CODE = 'wholesale'.freeze
- def call
- Spree::Store.find_each do |store|
- store.ensure_default_channel
+ private
- store.channels.find_or_create_by!(code: WHOLESALE_CODE) do |channel|
- channel.name = 'Wholesale'
- channel.preferred_storefront_access = 'login_required'
- channel.preferred_guest_checkout = false
- end
+ def seed(store)
+ store.ensure_default_channel
+
+ store.channels.find_or_create_by!(code: WHOLESALE_CODE) do |channel|
+ channel.name = 'Wholesale'
+ channel.preferred_storefront_access = 'login_required'
+ channel.preferred_guest_checkout = false
end
end
end
diff --git a/spree/core/app/services/spree/seeds/commission_rates.rb b/spree/core/app/services/spree/seeds/commission_rates.rb
index 794045850f..be1894d377 100644
--- a/spree/core/app/services/spree/seeds/commission_rates.rb
+++ b/spree/core/app/services/spree/seeds/commission_rates.rb
@@ -22,31 +22,32 @@ module Spree
# setting the value is the operator's first commission decision.
class CommissionRates
prepend Spree::ServiceModule::Base
+ include StoreScoped
DEFAULT_CODE = 'marketplace-default'.freeze
- def call
- Spree::Store.find_each do |store|
- # Live rows only, matching the partial unique index: an operator who
- # deleted the seeded fallback gets it back on the next run rather
- # than being left with no bottom-of-list catch-all forever.
- next if store.commission_rates.exists?(code: DEFAULT_CODE)
+ private
- rate = store.commission_rates.create!(
- name: Spree.t('seed.commission_rates.marketplace_default'),
- code: DEFAULT_CODE,
- kind: 'percentage',
- value: 0,
- enabled: false
- )
+ def seed(store)
+ # Live rows only, matching the partial unique index: an operator who
+ # deleted the seeded fallback gets it back on the next run rather
+ # than being left with no bottom-of-list catch-all forever.
+ return if store.commission_rates.exists?(code: DEFAULT_CODE)
- # New rates are born at the top, which is right for one an operator
- # adds and wrong for this one: it matches every sale, so anywhere but
- # the bottom leaves the rates below it unreachable. A store seeded
- # after it already has rates would otherwise have them all shadowed
- # the moment this was enabled.
- rate.move_to_bottom
- end
+ rate = store.commission_rates.create!(
+ name: Spree.t('seed.commission_rates.marketplace_default'),
+ code: DEFAULT_CODE,
+ kind: 'percentage',
+ value: 0,
+ enabled: false
+ )
+
+ # New rates are born at the top, which is right for one an operator
+ # adds and wrong for this one: it matches every sale, so anywhere but
+ # the bottom leaves the rates below it unreachable. A store seeded
+ # after it already has rates would otherwise have them all shadowed
+ # the moment this was enabled.
+ rate.move_to_bottom
end
end
end
diff --git a/spree/core/app/services/spree/seeds/customer_groups.rb b/spree/core/app/services/spree/seeds/customer_groups.rb
index 6a36e25cd1..7f709aaf52 100644
--- a/spree/core/app/services/spree/seeds/customer_groups.rb
+++ b/spree/core/app/services/spree/seeds/customer_groups.rb
@@ -5,13 +5,14 @@ module Spree
# wholesale price lists key off.
class CustomerGroups
prepend Spree::ServiceModule::Base
+ include StoreScoped
WHOLESALE_NAME = 'Wholesale'.freeze
- def call
- Spree::Store.find_each do |store|
- store.customer_groups.find_or_create_by!(name: WHOLESALE_NAME)
- end
+ private
+
+ def seed(store)
+ store.customer_groups.find_or_create_by!(name: WHOLESALE_NAME)
end
end
end
diff --git a/spree/core/app/services/spree/seeds/digital_delivery.rb b/spree/core/app/services/spree/seeds/digital_delivery.rb
index fc162c3be6..cc56cc8bf2 100644
--- a/spree/core/app/services/spree/seeds/digital_delivery.rb
+++ b/spree/core/app/services/spree/seeds/digital_delivery.rb
@@ -2,16 +2,11 @@ module Spree
module Seeds
class DigitalDelivery
prepend Spree::ServiceModule::Base
-
- def call
- Spree::Store.all.find_each do |store|
- create_for(store)
- end
- end
+ include StoreScoped
private
- def create_for(store)
+ def seed(store)
# Digital goods are a distinct product set, so they get their own
# profile; assigning a product to it is what makes it digital.
profile = Spree::DeliveryProfiles::Digital.find_by(store: store) ||
@@ -22,7 +17,11 @@ module Spree
digital_delivery_method.delivery_profile = profile
digital_delivery_method.storefront_visible = true
digital_delivery_method.fulfillment_provider = 'Spree::FulfillmentProvider::Digital'
- digital_delivery_method.calculator ||= Spree::Calculator::Shipping::DigitalDelivery.create!
+ # Explicit, because the calculator's own default is the default
+ # store's currency rather than this store's.
+ digital_delivery_method.calculator ||= Spree::Calculator::Shipping::DigitalDelivery.create!(
+ preferred_currency: store.default_currency
+ )
digital_delivery_method.save!
end
end
diff --git a/spree/core/app/services/spree/seeds/payment_methods.rb b/spree/core/app/services/spree/seeds/payment_methods.rb
index 3b2f913b06..9680b2308b 100644
--- a/spree/core/app/services/spree/seeds/payment_methods.rb
+++ b/spree/core/app/services/spree/seeds/payment_methods.rb
@@ -2,19 +2,20 @@ module Spree
module Seeds
class PaymentMethods
prepend Spree::ServiceModule::Base
+ include StoreScoped
- def call
- Spree::Store.all.find_each do |store|
- payment_method = store.payment_methods.find_or_initialize_by(
- type: 'Spree::PaymentMethod::StoreCredit'
- )
- next if payment_method.persisted?
+ private
- payment_method.name = Spree.t(:store_credit_name)
- payment_method.description = Spree.t(:store_credit_name)
- payment_method.active = true
- payment_method.save!
- end
+ def seed(store)
+ payment_method = store.payment_methods.find_or_initialize_by(
+ type: 'Spree::PaymentMethod::StoreCredit'
+ )
+ return if payment_method.persisted?
+
+ payment_method.name = Spree.t(:store_credit_name)
+ payment_method.description = Spree.t(:store_credit_name)
+ payment_method.active = true
+ payment_method.save!
end
end
end
diff --git a/spree/core/app/services/spree/seeds/product_types.rb b/spree/core/app/services/spree/seeds/product_types.rb
index eb9f84de16..92c1f1764d 100644
--- a/spree/core/app/services/spree/seeds/product_types.rb
+++ b/spree/core/app/services/spree/seeds/product_types.rb
@@ -2,18 +2,17 @@ module Spree
module Seeds
class ProductTypes
prepend Spree::ServiceModule::Base
+ include StoreScoped
- def call
- Spree::Store.all.find_each do |store|
- Spree::ProductType.where(store: store).find_or_create_by!(name: I18n.t('spree.seed.product_types.default'))
- Spree::ProductType.where(store: store).find_or_create_by!(name: I18n.t('spree.seed.product_types.digital')) do |product_type|
- product_type.delivery_profile = digital_profile_for(store)
- end
+ private
+
+ def seed(store)
+ Spree::ProductType.where(store: store).find_or_create_by!(name: I18n.t('spree.seed.product_types.default'))
+ Spree::ProductType.where(store: store).find_or_create_by!(name: I18n.t('spree.seed.product_types.digital')) do |product_type|
+ product_type.delivery_profile = digital_profile_for(store)
end
end
- private
-
def digital_profile_for(store)
Spree::DeliveryProfiles::Digital.find_by(store: store) ||
Spree::DeliveryProfiles::Digital.create!(store: store, name: I18n.t('spree.seed.delivery_profiles.digital'))
diff --git a/spree/core/app/services/spree/seeds/returns_environment.rb b/spree/core/app/services/spree/seeds/returns_environment.rb
index 88d3eb8142..9bfa8e567d 100644
--- a/spree/core/app/services/spree/seeds/returns_environment.rb
+++ b/spree/core/app/services/spree/seeds/returns_environment.rb
@@ -2,6 +2,7 @@ module Spree
module Seeds
class ReturnsEnvironment
prepend Spree::ServiceModule::Base
+ include StoreScoped
RETURN_REASONS = [
'Better price available',
@@ -37,18 +38,18 @@ module Spree
'Item not as described'
].freeze
- def call
- # Every vocabulary is store-owned, so every store gets its own.
- Spree::Store.all.find_each do |store|
- # Through the model helper, not a literal — the workflows look this
- # row up by the same constant, so a hard-coded string here would
- # silently create a second, unfindable reason if the name ever moves.
- Spree::RefundReason.return_processing_reason(store)
+ private
- RETURN_REASONS.each { |name| Spree::ReturnReason.where(store: store).find_or_create_by!(name: name) }
- CLAIM_REASONS.each { |name| Spree::ClaimReason.where(store: store).find_or_create_by!(name: name) }
- ORDER_CANCELLATION_REASONS.each { |name| Spree::OrderCancellationReason.where(store: store).find_or_create_by!(name: name) }
- end
+ # Every vocabulary is store-owned, so every store gets its own.
+ def seed(store)
+ # Through the model helper, not a literal — the workflows look this
+ # row up by the same constant, so a hard-coded string here would
+ # silently create a second, unfindable reason if the name ever moves.
+ Spree::RefundReason.return_processing_reason(store)
+
+ RETURN_REASONS.each { |name| Spree::ReturnReason.where(store: store).find_or_create_by!(name: name) }
+ CLAIM_REASONS.each { |name| Spree::ClaimReason.where(store: store).find_or_create_by!(name: name) }
+ ORDER_CANCELLATION_REASONS.each { |name| Spree::OrderCancellationReason.where(store: store).find_or_create_by!(name: name) }
end
end
end
diff --git a/spree/core/app/services/spree/seeds/roles.rb b/spree/core/app/services/spree/seeds/roles.rb
index db595c41d3..950d89ae12 100644
--- a/spree/core/app/services/spree/seeds/roles.rb
+++ b/spree/core/app/services/spree/seeds/roles.rb
@@ -1,15 +1,16 @@
module Spree
module Seeds
+ # A role belongs to what it governs, so every store gets its own
+ # immutable admin.
class Roles
prepend Spree::ServiceModule::Base
+ include StoreScoped
- # A role belongs to what it governs, so every store gets its own
- # immutable admin.
- def call
- Spree::Store.find_each do |store|
- admin = Spree::Role.default_admin_role(store)
- admin.update_column(:mutable, false) if admin.read_attribute(:mutable)
- end
+ private
+
+ def seed(store)
+ admin = Spree::Role.default_admin_role(store)
+ admin.update_column(:mutable, false) if admin.read_attribute(:mutable)
end
end
end
diff --git a/spree/core/app/services/spree/seeds/saved_reports.rb b/spree/core/app/services/spree/seeds/saved_reports.rb
index 3e4c6cd75c..8b04faf7bc 100644
--- a/spree/core/app/services/spree/seeds/saved_reports.rb
+++ b/spree/core/app/services/spree/seeds/saved_reports.rb
@@ -6,6 +6,7 @@ module Spree
# only never-created ones are added.
class SavedReports
prepend Spree::ServiceModule::Base
+ include StoreScoped
REPORTS = [
{ key: 'sales_over_time',
@@ -70,31 +71,29 @@ module Spree
'time_range' => { 'preset' => 'last_4_weeks' } } }
].freeze
- def call
- Spree::Store.find_each do |store|
- # Compared case-insensitively like the model's uniqueness rule, so a
- # merchant's own "top products" never makes a re-seed raise.
- existing = store.saved_reports.pluck(:name).map(&:downcase).to_set
+ private
+
+ def seed(store)
+ # Compared case-insensitively like the model's uniqueness rule, so a
+ # merchant's own "top products" never makes a re-seed raise.
+ existing = store.saved_reports.pluck(:name).map(&:downcase).to_set
- REPORTS.each do |report|
- # Every locale's name for this report, not just the current one:
- # the name is translated, so a store seeded in one language and
- # re-seeded in another would otherwise recognise none of its own
- # built-ins and create a second full set.
- next if known_names(report[:key]).intersect?(existing)
+ REPORTS.each do |report|
+ # Every locale's name for this report, not just the current one:
+ # the name is translated, so a store seeded in one language and
+ # re-seeded in another would otherwise recognise none of its own
+ # built-ins and create a second full set.
+ next if known_names(report[:key]).intersect?(existing)
- store.saved_reports.create!(
- name: Spree.t("reporting.seeds.#{report[:key]}.name"),
- description: Spree.t("reporting.seeds.#{report[:key]}.description"),
- query: report[:query],
- seeded: true
- )
- end
+ store.saved_reports.create!(
+ name: Spree.t("reporting.seeds.#{report[:key]}.name"),
+ description: Spree.t("reporting.seeds.#{report[:key]}.description"),
+ query: report[:query],
+ seeded: true
+ )
end
end
- private
-
# The downcased name this report carries in every locale core ships.
def known_names(key)
@known_names ||= {}
diff --git a/spree/core/app/services/spree/seeds/seller_requirements.rb b/spree/core/app/services/spree/seeds/seller_requirements.rb
index 3825b7fb05..b5dfa0a93d 100644
--- a/spree/core/app/services/spree/seeds/seller_requirements.rb
+++ b/spree/core/app/services/spree/seeds/seller_requirements.rb
@@ -8,11 +8,12 @@ module Spree
# a licence) is theirs to add, and there is no sensible default for it.
class SellerRequirements
prepend Spree::ServiceModule::Base
+ include StoreScoped
- def call
- Spree::Store.find_each do |store|
- Spree::SellerRequirement.provision_defaults(store)
- end
+ private
+
+ def seed(store)
+ Spree::SellerRequirement.provision_defaults(store)
end
end
end
diff --git a/spree/core/app/services/spree/seeds/store_resources.rb b/spree/core/app/services/spree/seeds/store_resources.rb
new file mode 100644
index 0000000000..2a843cbbe6
--- /dev/null
+++ b/spree/core/app/services/spree/seeds/store_resources.rb
@@ -0,0 +1,41 @@
+module Spree
+ module Seeds
+ # Seeds what a single store needs to trade, without touching any other
+ # store.
+ #
+ # Country-shaped defaults (market, warehouse, delivery zones, pickup) are
+ # not part of it: the caller runs Spree::Stores::ProvisionDefaults
+ # afterwards with the merchant's answers.
+ class StoreResources
+ prepend Spree::ServiceModule::Base
+
+ # @param store [Spree::Store] the store to seed, already persisted
+ # @return [Spree::ServiceModule::Result]
+ def call(store:)
+ # A nil store would fall through to every seed's all-stores mode.
+ raise ArgumentError, 'store is required' if store.nil?
+
+ Spree::Events.disable do
+ ActiveRecord::Base.no_touching do
+ TaxCategories.call(store: store)
+ Channels.call(store: store)
+ Roles.call(store: store)
+ DigitalDelivery.call(store: store)
+ PaymentMethods.call(store: store)
+ ProductTypes.call(store: store)
+ CustomerGroups.call(store: store)
+ ReturnsEnvironment.call(store: store)
+ # The marketplace's catch-all rate, at the bottom of the list so
+ # narrower rates added later resolve ahead of it.
+ CommissionRates.call(store: store)
+ SellerRequirements.call(store: store)
+ # Binds to the wholesale channel that Channels creates above.
+ ApiKeys.call(store: store)
+ SavedReports.call(store: store)
+ AllowedOrigins.call(store: store)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/seeds/store_scoped.rb b/spree/core/app/services/spree/seeds/store_scoped.rb
new file mode 100644
index 0000000000..7838a9312f
--- /dev/null
+++ b/spree/core/app/services/spree/seeds/store_scoped.rb
@@ -0,0 +1,15 @@
+module Spree
+ module Seeds
+ # Shared entry point for seeds whose rows belong to a store. Including
+ # classes implement a private `seed(store)` that seeds exactly one store
+ # and is safe to re-run.
+ module StoreScoped
+ # @param store [Spree::Store, nil] the store to seed; every store when nil
+ def call(store: nil)
+ return seed(store) if store
+
+ Spree::Store.find_each { |each_store| seed(each_store) }
+ end
+ end
+ end
+end
diff --git a/spree/core/app/services/spree/seeds/tax_categories.rb b/spree/core/app/services/spree/seeds/tax_categories.rb
index 62c80a8ede..8c680e1144 100644
--- a/spree/core/app/services/spree/seeds/tax_categories.rb
+++ b/spree/core/app/services/spree/seeds/tax_categories.rb
@@ -2,17 +2,18 @@ module Spree
module Seeds
class TaxCategories
prepend Spree::ServiceModule::Base
+ include StoreScoped
- def call
- Spree::Store.find_each do |store|
- # The block form only runs on create, so a store that already had a
- # "Default" category with the flag unset kept no default at all — and
- # the default is what taxes an item carrying no category of its own.
- default = store.tax_categories.find_or_create_by!(name: 'Default')
- default.update!(is_default: true) unless default.is_default?
+ private
- store.tax_categories.find_or_create_by!(name: 'Non-taxable')
- end
+ def seed(store)
+ # The block form only runs on create, so a store that already had a
+ # "Default" category with the flag unset kept no default at all — and
+ # the default is what taxes an item carrying no category of its own.
+ default = store.tax_categories.find_or_create_by!(name: 'Default')
+ default.update!(is_default: true) unless default.is_default?
+
+ store.tax_categories.find_or_create_by!(name: 'Non-taxable')
end
end
end
diff --git a/spree/core/spec/services/spree/seeds/all_spec.rb b/spree/core/spec/services/spree/seeds/all_spec.rb
index 23109c3aad..b761f9cd31 100644
--- a/spree/core/spec/services/spree/seeds/all_spec.rb
+++ b/spree/core/spec/services/spree/seeds/all_spec.rb
@@ -7,6 +7,18 @@ RSpec.describe Spree::Seeds::All do
expect { subject }.not_to raise_error
end
+ it 'seeds every store' do
+ other_store = create(:store)
+
+ subject
+
+ [@default_store, other_store].each do |store|
+ expect(store.tax_categories).to exist
+ expect(store.saved_reports).to exist
+ expect(store.api_keys).to exist
+ end
+ end
+
# CI seeds a fresh app and re-seeds on rerun; a seed whose finder includes
# mutable attributes stops matching once anything edits them and then tries
# to create a duplicate.
diff --git a/spree/core/spec/services/spree/seeds/store_resources_spec.rb b/spree/core/spec/services/spree/seeds/store_resources_spec.rb
new file mode 100644
index 0000000000..735568558d
--- /dev/null
+++ b/spree/core/spec/services/spree/seeds/store_resources_spec.rb
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+RSpec.describe Spree::Seeds::StoreResources do
+ let(:store) { create(:store, default_currency: 'EUR') }
+ let!(:other_store) { create(:store) }
+
+ let(:seeded_counts) do
+ lambda do |seeded_store|
+ {
+ tax_categories: seeded_store.tax_categories.count,
+ channels: seeded_store.channels.count,
+ roles: Spree::Role.for_resource(seeded_store).count,
+ delivery_methods: Spree::DeliveryMethod.where(store: seeded_store).count,
+ payment_methods: seeded_store.payment_methods.count,
+ product_types: Spree::ProductType.where(store: seeded_store).count,
+ customer_groups: seeded_store.customer_groups.count,
+ return_reasons: Spree::ReturnReason.where(store: seeded_store).count,
+ commission_rates: seeded_store.commission_rates.count,
+ seller_requirements: seeded_store.seller_requirements.count,
+ api_keys: seeded_store.api_keys.count,
+ saved_reports: seeded_store.saved_reports.count,
+ allowed_origins: seeded_store.allowed_origins.count
+ }
+ end
+ end
+
+ it 'seeds the given store and leaves every other store untouched' do
+ other_before = seeded_counts.call(other_store)
+ default_before = seeded_counts.call(@default_store)
+
+ described_class.call(store: store)
+
+ expect(seeded_counts.call(store).values).to all(be_positive)
+ expect(seeded_counts.call(other_store)).to eq(other_before)
+ expect(seeded_counts.call(@default_store)).to eq(default_before)
+ end
+
+ it 'is idempotent' do
+ described_class.call(store: store)
+
+ expect { described_class.call(store: store) }.not_to(change { seeded_counts.call(store) })
+ end
+
+ it "prices digital delivery in the store's own currency" do
+ described_class.call(store: store)
+
+ digital = Spree::DeliveryMethod.find_by!(store: store, fulfillment_provider: 'Spree::FulfillmentProvider::Digital')
+ expect(digital.calculator.preferred_currency).to eq('EUR')
+ end
+
+ it 'refuses to run without a store' do
+ expect { described_class.call(store: nil) }.to raise_error(ArgumentError)
+ end
+end
diff --git a/spree/core/spec/services/spree/seeds/tax_categories_spec.rb b/spree/core/spec/services/spree/seeds/tax_categories_spec.rb
index 6348d8a17f..6df7b25f5b 100644
--- a/spree/core/spec/services/spree/seeds/tax_categories_spec.rb
+++ b/spree/core/spec/services/spree/seeds/tax_categories_spec.rb
@@ -31,6 +31,15 @@ RSpec.describe Spree::Seeds::TaxCategories do
expect(@default_store.tax_categories.find_by(is_default: true).name).to eq('Default')
end
+ it 'seeds only the store it is given' do
+ other_store = create(:store)
+
+ described_class.call(store: other_store)
+
+ expect(other_store.tax_categories.pluck(:name)).to match_array(expected_categories.pluck(:name))
+ expect(@default_store.tax_categories).to be_empty
+ end
+
context 'when TaxCategories already exist' do
before do
expected_categories.each do |category_attrs|