From bdbeb2feb800ed28cbfabb3b4c983c2f41808ba3 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:39:35 +0000 Subject: [PATCH 01/10] Require missing dependency in VariantOverride --- app/models/variant_override.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index ad4369ea51..f090d7e7b9 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -1,3 +1,5 @@ +require 'spree/localized_number' + class VariantOverride < ActiveRecord::Base extend Spree::LocalizedNumber include StockSettingsOverrideValidation From ee0da876814a1eff25abdd870154985437af2132 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 16:14:50 +0000 Subject: [PATCH 02/10] Fix touch call to unsaved object Failure/Error: enterprise.andand.touch ActiveRecord::ActiveRecordError: cannot touch on a new or destroyed record object. Consider using persisted?, new_record?, or destroyed? before touching # ./app/models/spree/address.rb:155:in `touch_enterprise' # ./spec/factories/product_factory.rb:12:in `block (3 levels) in ' # ./spec/factories/variant_factory.rb:26:in `block (4 levels) in ' # ./spec/models/spree/variant_spec.rb:9:in `block (2 levels) in ' --- app/models/spree/address.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index 5dbd0dd535..855cfa67d1 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -152,7 +152,9 @@ module Spree end def touch_enterprise - enterprise.andand.touch + return unless enterprise&.persisted? + + enterprise.touch end def render_address(parts) From eb5c37daca038adfe514472a6605eb66de06b0b6 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 17:03:28 +0000 Subject: [PATCH 03/10] Change order of declaration for has_many_through association with it's parent Fixes: 292) OrderManagement::Subscriptions::ProxyOrderSyncer#sync! when the subscription is not persisted and the schedule includes upcoming oc that closes after ends_at does not create a new proxy order for that oc Failure/Error: order_cycle.schedules << schedule ActiveRecord::HasManyThroughOrderError: Cannot have a has_many :through association 'OrderCycle#schedules' which goes through 'OrderCycle#order_cycle_schedules' before the through association is defined. # ./spec/factories.rb:29:in `block (4 levels) in ' # ./spec/factories.rb:28:in `each' # ./spec/factories.rb:28:in `block (3 levels) in ' # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:59:in `block (4 levels) in ' # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:65:in `block (4 levels) in ' # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:133:in `block (6 levels) in ' # ./engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb:133:in `block (5 levels) in ' --- app/models/order_cycle.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 93451f081c..91230b3aec 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -16,8 +16,8 @@ class OrderCycle < ActiveRecord::Base has_many :suppliers, -> { distinct }, source: :sender, through: :cached_incoming_exchanges has_many :distributors, -> { distinct }, source: :receiver, through: :cached_outgoing_exchanges - has_many :schedules, through: :order_cycle_schedules has_many :order_cycle_schedules + has_many :schedules, through: :order_cycle_schedules has_paper_trail meta: { custom_data: proc { |order_cycle| order_cycle.schedule_ids.to_s } } attr_accessor :incoming_exchanges, :outgoing_exchanges From a7fd64d7bfe80316c207010e10b2daf6fdf1ef26 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 18:25:47 +0000 Subject: [PATCH 04/10] Update has_many_through on Schedule --- app/models/schedule.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/schedule.rb b/app/models/schedule.rb index 5fe5da3205..3b94059c20 100644 --- a/app/models/schedule.rb +++ b/app/models/schedule.rb @@ -1,9 +1,8 @@ class Schedule < ActiveRecord::Base has_paper_trail meta: { custom_data: proc { |schedule| schedule.order_cycle_ids.to_s } } - has_many :order_cycles, through: :order_cycle_schedules has_many :order_cycle_schedules, dependent: :destroy - + has_many :order_cycles, through: :order_cycle_schedules has_many :coordinators, -> { uniq }, through: :order_cycles scope :with_coordinator, lambda { |enterprise| joins(:order_cycles).where('coordinator_id = ?', enterprise.id).select('DISTINCT schedules.*') } From ab18a2e60c01df78dd42302dc0cee21550934d40 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 11 Mar 2021 22:03:46 +0000 Subject: [PATCH 05/10] [Rails 5] change #process method call args for upgraded rails Copied from spree https://github.com/spree/spree/commit/a5e14e3313adf33f68b50753649037a64014f0af --- spec/support/controller_requests_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/support/controller_requests_helper.rb b/spec/support/controller_requests_helper.rb index fa02ed71d1..4b992f5949 100644 --- a/spec/support/controller_requests_helper.rb +++ b/spec/support/controller_requests_helper.rb @@ -47,9 +47,9 @@ module ControllerRequestsHelper def process_action_with_route(action, params = {}, session = nil, flash = nil, method = "GET") process(action, - method, - params.reverse_merge!(use_route: :main_app), - session, - flash) + method: method, + params: params.reverse_merge!(use_route: :main_app), + session: session, + flash: flash) end end From 6132f4bf18d21a35e8247ad46adc0520ed86c534 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 4 Mar 2021 13:22:04 +0000 Subject: [PATCH 06/10] Don't pass string to conditional in validation --- app/models/spree/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 09b239855b..9355db8830 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -90,7 +90,7 @@ module Spree validates :supplier, presence: true validates :primary_taxon, presence: true - validates :tax_category_id, presence: true, if: "Spree::Config.products_require_tax_category" + validates :tax_category_id, presence: true, if: Spree::Config.products_require_tax_category validates :variant_unit, presence: true validates :unit_value, presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } } From d5443cf4896ee0857d4c89e848c31d183c469aa6 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 17:09:00 +0000 Subject: [PATCH 07/10] Update has_many_through on ShippingMethod Fixes: 259) Spree::ShippingMethod#shipments can gather all the related shipments Failure/Error: expect(shipping_method.shipments).to include(shipment) ActiveRecord::HasManyThroughOrderError: Cannot have a has_many :through association 'Spree::ShippingMethod#shipments' which goes through 'Spree::ShippingMethod#shipping_rates' before the through association is defined. # ./spec/models/spree/shipping_method_spec.rb:190:in `block (3 levels) in ' --- app/models/spree/shipping_method.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/shipping_method.rb b/app/models/spree/shipping_method.rb index 909ed9c99f..426d658b43 100644 --- a/app/models/spree/shipping_method.rb +++ b/app/models/spree/shipping_method.rb @@ -10,10 +10,10 @@ module Spree default_scope -> { where(deleted_at: nil) } + has_many :shipping_rates, inverse_of: :shipping_method has_many :shipments, through: :shipping_rates has_many :shipping_method_categories has_many :shipping_categories, through: :shipping_method_categories - has_many :shipping_rates, inverse_of: :shipping_method has_many :distributor_shipping_methods has_many :distributors, through: :distributor_shipping_methods, class_name: 'Enterprise', From 77b0e2d23f53497d500615bd4f5ae857b100f43a Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 17:12:03 +0000 Subject: [PATCH 08/10] Update has_many_through on Order Fixes: 384) Spree::OrderMailer basic behaviour doesn't aggressively escape double quotes in confirmation body Failure/Error: adjustments = adjustments.to_a + order.shipment_adjustments.to_a ActionView::Template::Error: Cannot have a has_many :through association 'Spree::Order#shipment_adjustments' which goes through 'Spree::Order#shipments' before the through association is defined. # ./app/helpers/checkout_helper.rb:10:in `checkout_adjustments_for' # ./app/views/spree/order_mailer/_order_summary.html.haml:43:in `_app_views_spree_order_mailer__order_summary_html_haml__2911251238692323485_70331958934800' # ./app/views/spree/order_mailer/confirm_email_for_customer.html.haml:23:in `_app_views_spree_order_mailer_confirm_email_for_customer_html_haml__3734564010704881256_70331959518520' # ./app/mailers/spree/order_mailer.rb:35:in `block in confirm_email_for_customer' # ./app/mailers/spree/order_mailer.rb:33:in `confirm_email_for_customer' # ./spec/mailers/order_mailer_spec.rb:20:in `block (3 levels) in ' # ------------------ # --- Caused by: --- # ActiveRecord::HasManyThroughOrderError: # Cannot have a has_many :through association 'Spree::Order#shipment_adjustments' which goes through 'Spree::Order#shipments' before the through association is defined. # ./app/helpers/checkout_helper.rb:10:in `checkout_adjustments_for' --- app/models/spree/order.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index b1731b42d4..4093c995f8 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -42,16 +42,16 @@ module Spree as: :adjustable, dependent: :destroy - has_many :line_item_adjustments, through: :line_items, source: :adjustments - has_many :shipment_adjustments, through: :shipments, source: :adjustments - has_many :all_adjustments, class_name: 'Spree::Adjustment', dependent: :destroy - has_many :shipments, dependent: :destroy do def states pluck(:state).uniq end end + has_many :line_item_adjustments, through: :line_items, source: :adjustments + has_many :shipment_adjustments, through: :shipments, source: :adjustments + has_many :all_adjustments, class_name: 'Spree::Adjustment', dependent: :destroy + belongs_to :order_cycle belongs_to :distributor, class_name: 'Enterprise' belongs_to :customer From 3853aed718fc23f083a7a239e53c73ceee5267b8 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 22 Mar 2021 21:01:56 +0000 Subject: [PATCH 09/10] Make validator work in rails 5 and rails 5.2 by adding a proc --- app/models/spree/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 9355db8830..f1e4ebf696 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -90,7 +90,7 @@ module Spree validates :supplier, presence: true validates :primary_taxon, presence: true - validates :tax_category_id, presence: true, if: Spree::Config.products_require_tax_category + validates :tax_category_id, presence: true, if: proc { Spree::Config.products_require_tax_category } validates :variant_unit, presence: true validates :unit_value, presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } } From 13b8b3d4a5fe89f768d9a62f97152050be5130c2 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 22 Mar 2021 23:24:01 +0000 Subject: [PATCH 10/10] Fix rubocop issues --- app/models/spree/product.rb | 3 ++- app/models/variant_override.rb | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index f1e4ebf696..de66967992 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -90,7 +90,8 @@ module Spree validates :supplier, presence: true validates :primary_taxon, presence: true - validates :tax_category_id, presence: true, if: proc { Spree::Config.products_require_tax_category } + validates :tax_category_id, presence: true, + if: proc { Spree::Config.products_require_tax_category } validates :variant_unit, presence: true validates :unit_value, presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } } diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index f090d7e7b9..d17b7ff0d8 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spree/localized_number' class VariantOverride < ActiveRecord::Base