From 9a511e9e940e8d97d20cc357823085fa23563445 Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Fri, 17 Jun 2022 12:55:17 +0100 Subject: [PATCH] Rubocop adjustments --- app/models/order_cycle_shipping_method.rb | 2 +- app/services/order_available_shipping_methods.rb | 8 +++++++- spec/factories/order_cycle_factory.rb | 2 -- spec/models/order_cycle_shipping_method_spec.rb | 6 ++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/models/order_cycle_shipping_method.rb b/app/models/order_cycle_shipping_method.rb index fa9c362edb..4d53a2f3bf 100644 --- a/app/models/order_cycle_shipping_method.rb +++ b/app/models/order_cycle_shipping_method.rb @@ -7,7 +7,7 @@ class OrderCycleShippingMethod < ApplicationRecord validate :shipping_method_belongs_to_order_cycle_distributor validate :shipping_method_available_at_checkout validate :order_cycle_not_simple - validates_uniqueness_of :shipping_method, scope: :order_cycle_id + validates :shipping_method, uniqueness: { scope: :order_cycle_id } before_destroy :check_shipping_method_not_selected_on_any_orders diff --git a/app/services/order_available_shipping_methods.rb b/app/services/order_available_shipping_methods.rb index 3c815d19a0..36fd37f2c8 100644 --- a/app/services/order_available_shipping_methods.rb +++ b/app/services/order_available_shipping_methods.rb @@ -1,10 +1,16 @@ # frozen_string_literal: true -class OrderAvailableShippingMethods < Struct.new(:order, :customer) +class OrderAvailableShippingMethods + attr_reader :order, :customer + delegate :distributor, :order_cycle, to: :order + def initialize(order, customer = nil) + @order, @customer = order, customer + end + def to_a return [] if distributor.blank? diff --git a/spec/factories/order_cycle_factory.rb b/spec/factories/order_cycle_factory.rb index 1962475a8d..469fb94019 100644 --- a/spec/factories/order_cycle_factory.rb +++ b/spec/factories/order_cycle_factory.rb @@ -72,14 +72,12 @@ FactoryBot.define do coordinator { Enterprise.is_distributor.first || FactoryBot.create(:distributor_enterprise) } transient do - shipping_methods { [] } suppliers { [] } distributors { [] } variants { [] } end after(:create) do |oc, proxy| - # Incoming Exchanges proxy.suppliers.each.with_index do |supplier, i| ex = create(:exchange, order_cycle: oc, diff --git a/spec/models/order_cycle_shipping_method_spec.rb b/spec/models/order_cycle_shipping_method_spec.rb index bb503182fb..352cee2565 100644 --- a/spec/models/order_cycle_shipping_method_spec.rb +++ b/spec/models/order_cycle_shipping_method_spec.rb @@ -47,7 +47,8 @@ describe OrderCycleShippingMethod do expect(order_cycle_shipping_method).to_not be_valid expect(order_cycle_shipping_method.errors.to_a).to include( - "Order cycle is simple, all shipping methods are available by default and cannot be customised" + "Order cycle is simple, all shipping methods are available by default and cannot be " \ + "customised" ) end @@ -108,7 +109,8 @@ describe OrderCycleShippingMethod do expect(order_cycle_shipping_method).not_to be_destroyed expect(order_cycle_shipping_method.errors.to_a).to eq [ - "This shipping method has already been selected on orders in this order cycle and cannot be removed" + "This shipping method has already been selected on orders in this order cycle and cannot " \ + "be removed" ] end end