Skip to content

Commit

Permalink
Deprecate Spree::NamedType
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elia committed Dec 6, 2023
1 parent c4115d7 commit 20535a7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions core/app/models/concerns/spree/named_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
5 changes: 4 additions & 1 deletion core/app/models/spree/refund_reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 4 additions & 1 deletion core/app/models/spree/reimbursement_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 4 additions & 1 deletion core/app/models/spree/return_reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion core/app/models/spree/store_credit_reason.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 20535a7

Please sign in to comment.