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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Replace case sensitive validation of product slugs for better performance
Damian Legawiec7a5a9f590671
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rbindex 183c71f4b3..40b01e8616 100644--- a/core/app/models/spree/product.rb+++ b/core/app/models/spree/product.rb@@ -99,6 +99,7 @@ module Spreeafter_save :reset_memoized_dataafter_commit :reset_memoized_data+ before_validation :downcase_slugbefore_validation :normalize_slug, on: :updatebefore_validation :validate_master@@ -112,7 +113,7 @@ module Spreevalidates :price, if: :requires_price?end- validates :slug, presence: true, uniqueness: { allow_blank: true, case_sensitive: false }+ validates :slug, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }validate :discontinue_on_must_be_later_than_available_on, if: -> { available_on && discontinue_on }attr_accessor :option_values_hash@@ -499,5 +500,9 @@ module Spreedef requires_shipping_category?trueend++ def downcase_slug+ slug&.downcase!+ endendenddiff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rbindex 56b1032589..35ed46afd9 100644--- a/core/spec/models/spree/product_spec.rb+++ b/core/spec/models/spree/product_spec.rb@@ -750,4 +750,10 @@ describe '#default_variant_cache_key' doit { expect(product.save).to eq(false) }end++ describe '#downcase_slug' do+ let(:product) { build(:product, slug: 'My-slug') }++ it { expect { product.valid? }.to change(product, :slug).to('my-slug') }+ endend