From 87f0be42e22d81272c50c770460beac1e3591b47 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Tue, 4 Jun 2024 18:12:37 +0200 Subject: [PATCH] Fixes rubocop offenses on Spree::Order model - removes old Rails 5 flag to not validating belongs to association. Therefore optional fields must be marked so. --- .rubocop_todo.yml | 6 ------ app/models/spree/order.rb | 16 +++++++--------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b99b52a9a8b..fc721d94cc7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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: diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 03fdf5208cc..e8974272c4a 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -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 @@ -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 @@ -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