Skip to content

Commit

Permalink
Fixes rubocop offenses on Spree::Order model
Browse files Browse the repository at this point in the history
- removes old Rails 5 flag to not validating
belongs to association. Therefore optional fields must be marked so.
  • Loading branch information
cyrillefr committed Jun 4, 2024
1 parent db255b0 commit 87f0be4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,6 @@ Rails/RedundantActiveRecordAllMethod:
- 'app/models/spree/variant.rb'
- 'spec/system/admin/product_import_spec.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/RedundantPresenceValidationOnBelongsTo:
Exclude:
- 'app/models/spree/order.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/RelativeDateConstant:
Expand Down
16 changes: 7 additions & 9 deletions app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class Order < ApplicationRecord
include Balance
include SetUnusedAddressFields

self.belongs_to_required_by_default = false

searchable_attributes :number, :state, :shipment_state, :payment_state, :distributor_id,
:order_cycle_id, :email, :total, :customer_id
searchable_associations :shipping_method, :bill_address, :distributor
Expand All @@ -33,13 +31,13 @@ class Order < ApplicationRecord

token_resource

belongs_to :user, class_name: "Spree::User"
belongs_to :created_by, class_name: "Spree::User"
belongs_to :user, class_name: "Spree::User", optional: true
belongs_to :created_by, class_name: "Spree::User", optional: true

belongs_to :bill_address, class_name: 'Spree::Address'
belongs_to :bill_address, class_name: 'Spree::Address', optional: true
alias_attribute :billing_address, :bill_address

belongs_to :ship_address, class_name: 'Spree::Address'
belongs_to :ship_address, class_name: 'Spree::Address', optional: true
alias_attribute :shipping_address, :ship_address

has_many :state_changes, as: :stateful, dependent: :destroy
Expand Down Expand Up @@ -70,9 +68,9 @@ def states
dependent: :destroy
has_many :invoices, dependent: :restrict_with_exception

belongs_to :order_cycle
belongs_to :distributor, class_name: 'Enterprise'
belongs_to :customer
belongs_to :order_cycle, optional: true
belongs_to :distributor, class_name: 'Enterprise', optional: true
belongs_to :customer, optional: true
has_one :proxy_order, dependent: :destroy
has_one :subscription, through: :proxy_order

Expand Down

0 comments on commit 87f0be4

Please sign in to comment.