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.

add acts_as_paranoid for store translations + fix broken tests

nciemniak988d80249f66
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 97835f0a96..c88dce9759 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -12,7 +12,12 @@ module Spree
supported_currencies facebook twitter instagram customer_support_email
default_country_id description address contact_phone new_order_notifications_email
checkout_zone_id].freeze
- translate(*TRANSLATABLE_FIELDS)
+ translates(*TRANSLATABLE_FIELDS)
+
+ self::Translation.class_eval do
+ acts_as_paranoid
+ default_scope { unscope(where: :deleted_at) }
+ end
typed_store :settings, coder: ActiveRecord::TypedStore::IdentityCoder do |s|
# Spree Digital Asset Configurations
@@ -101,7 +106,7 @@ module Spree
before_destroy :validate_not_last, unless: :skip_validate_not_last
before_destroy :pass_default_flag_to_other_store
- scope :by_url, ->(url) { where('url like ?', "%#{url}%") }
+ scope :by_url, ->(url_param) { i18n { url.matches("%#{url_param}%") } }
after_commit :clear_cache
@@ -136,7 +141,7 @@ module Spree
end
def supported_currencies_list
- @supported_currencies_list ||= (read_attribute(:supported_currencies).to_s.split(',') << default_currency).sort.map(&:to_s).map do |code|
+ @supported_currencies_list ||= (supported_currencies.split(',') << default_currency).sort.map(&:to_s).map do |code|
::Money::Currency.find(code.strip)
end.uniq.compact
end
diff --git a/core/db/migrate/20230210230434_add_deleted_at_to_store_translations.rb b/core/db/migrate/20230210230434_add_deleted_at_to_store_translations.rb
new file mode 100644
index 0000000000..a743dbf273
--- /dev/null
+++ b/core/db/migrate/20230210230434_add_deleted_at_to_store_translations.rb
@@ -0,0 +1,6 @@
+class AddDeletedAtToStoreTranslations < ActiveRecord::Migration[6.1]
+ def change
+ add_column :spree_store_translations, :deleted_at, :datetime
+ add_index :spree_store_translations, :deleted_at
+ end
+end
diff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rb
index 6b841ecdf8..15e3ae0514 100644
--- a/core/spec/models/spree/store_spec.rb
+++ b/core/spec/models/spree/store_spec.rb
@@ -183,8 +183,8 @@ describe Spree::Store, type: :model do
end
it 'returns store for domain' do
- expect(subject.class.current('spreecommerce.com')).to eql(store_1)
- expect(subject.class.current('www.subdomain.com')).to eql(store_2)
+ expect(Spree::Stores::FindCurrent.new(url: 'spreecommerce.com').execute).to eql(store_1)
+ expect(Spree::Stores::FindCurrent.new(url: 'www.subdomain.com').execute).to eql(store_2)
end
end
@@ -225,13 +225,20 @@ describe Spree::Store, type: :model do
end
context 'when a default store is not present' do
- it 'builds a new default store' do
+ before do
+ described_class::Translation.delete_all
described_class.delete_all
Rails.cache.clear
+ end
+
+ it 'builds a new default store' do
expect(described_class.default.class).to eq(described_class)
- expect(described_class.default.persisted?).to eq(false)
expect(described_class.default.default).to be(true)
end
+
+ it 'does not persist the original default store' do
+ expect(described_class.default.persisted?).to eq(false)
+ end
end
end