From af0c7d31474a6226dd23d8f47f918a18503761f5 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 6 Dec 2023 10:54:32 +0100 Subject: [PATCH] Deprecate Spree::NamedType This module was a pretend shared behavior while the inlcuding classes were not related. Eventually we'll replace some of the default scopes with regular sorting scopes since default scopes often cause issues. Co-Authored-By: Rainer Dema --- core/app/models/concerns/spree/named_type.rb | 2 ++ core/app/models/spree/refund_reason.rb | 5 ++++- core/app/models/spree/reimbursement_type.rb | 5 ++++- core/app/models/spree/return_reason.rb | 5 ++++- core/app/models/spree/store_credit_reason.rb | 5 ++++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/app/models/concerns/spree/named_type.rb b/core/app/models/concerns/spree/named_type.rb index b3fc4d7c905..58e026b0ce0 100644 --- a/core/app/models/concerns/spree/named_type.rb +++ b/core/app/models/concerns/spree/named_type.rb @@ -5,6 +5,8 @@ module NamedType extend ActiveSupport::Concern included do + Spree.deprecator.warn "Spree::NamedType is deprecated. Please set scopes and validations locally instead.", caller + scope :active, -> { where(active: true) } default_scope -> { order(arel_table[:name].lower) } diff --git a/core/app/models/spree/refund_reason.rb b/core/app/models/spree/refund_reason.rb index 9247ae95929..a2b2e71db0a 100644 --- a/core/app/models/spree/refund_reason.rb +++ b/core/app/models/spree/refund_reason.rb @@ -2,7 +2,10 @@ module Spree class RefundReason < Spree::Base - include Spree::NamedType + scope :active, -> { where(active: true) } + default_scope -> { order(arel_table[:name].lower) } + + validates :name, presence: true, uniqueness: { case_sensitive: false, allow_blank: true } RETURN_PROCESSING_REASON = 'Return processing' diff --git a/core/app/models/spree/reimbursement_type.rb b/core/app/models/spree/reimbursement_type.rb index a669b9a37ba..1e652d8c2c0 100644 --- a/core/app/models/spree/reimbursement_type.rb +++ b/core/app/models/spree/reimbursement_type.rb @@ -2,7 +2,10 @@ module Spree class ReimbursementType < Spree::Base - include Spree::NamedType + scope :active, -> { where(active: true) } + default_scope -> { order(arel_table[:name].lower) } + + validates :name, presence: true, uniqueness: { case_sensitive: false, allow_blank: true } ORIGINAL = 'original' diff --git a/core/app/models/spree/return_reason.rb b/core/app/models/spree/return_reason.rb index aa41cdcdf42..601b26b6d7e 100644 --- a/core/app/models/spree/return_reason.rb +++ b/core/app/models/spree/return_reason.rb @@ -2,7 +2,10 @@ module Spree class ReturnReason < Spree::Base - include Spree::NamedType + scope :active, -> { where(active: true) } + default_scope -> { order(arel_table[:name].lower) } + + validates :name, presence: true, uniqueness: { case_sensitive: false, allow_blank: true } has_many :return_authorizations diff --git a/core/app/models/spree/store_credit_reason.rb b/core/app/models/spree/store_credit_reason.rb index c0b7b5e6abf..f8fdfa5cf08 100644 --- a/core/app/models/spree/store_credit_reason.rb +++ b/core/app/models/spree/store_credit_reason.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true class Spree::StoreCreditReason < Spree::Base - include Spree::NamedType + scope :active, -> { where(active: true) } + default_scope -> { order(arel_table[:name].lower) } + + validates :name, presence: true, uniqueness: { case_sensitive: false, allow_blank: true } has_many :store_credit_events, inverse_of: :store_credit_reason end