Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Spree::NamedType Concern #5541

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
  • Loading branch information
elia and rainerdema committed Dec 6, 2023
commit af0c7d31474a6226dd23d8f47f918a18503761f5
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) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any value in having this "metaprogramming" now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, default scopes are troublemakers and eventually we'd like to migrate them to regular scopes (e.g. scope :order_by_name …) so they don't get in the way with other things (joins, batch loading, …). While checking where the default scopes were defined we thought that this "concern" was not actually shared behavior but would be better off as local model features.

I hope I got the question right, otherwise let me know 🙏

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kennyadsl see also b2d4a7c


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