From b7abe290ec6f077e120d52fe1a532eb2109b8a62 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Fri, 5 May 2023 13:12:59 +1000 Subject: [PATCH] Remove non need belongs_to associations from Adjustments It turns out the "tax_rate" association isn't used and wasn't working. Same for the "voucher" one, which I added to be consistent with existing code. Both of these weren't caught by the specs because you can't test associations with a custome relation with 'shouda-matchers' see: https://github.com/thoughtbot/shoulda-matchers/issues/981 --- app/models/spree/adjustment.rb | 5 ----- app/models/voucher.rb | 1 - spec/models/spree/adjustment_spec.rb | 4 ---- 3 files changed, 10 deletions(-) diff --git a/app/models/spree/adjustment.rb b/app/models/spree/adjustment.rb index e0a4c1c5e57..57ef3d549c7 100644 --- a/app/models/spree/adjustment.rb +++ b/app/models/spree/adjustment.rb @@ -42,11 +42,6 @@ class Adjustment < ApplicationRecord belongs_to :order, class_name: "Spree::Order" belongs_to :tax_category, class_name: 'Spree::TaxCategory' - belongs_to :tax_rate, -> { where spree_adjustments: { originator_type: 'Spree::TaxRate' } }, - foreign_key: 'originator_id' - belongs_to :voucher, -> { where spree_adjustments: { originator_type: 'Voucher' } }, - foreign_key: 'originator_id', inverse_of: :adjustments - validates :label, presence: true validates :amount, numericality: true diff --git a/app/models/voucher.rb b/app/models/voucher.rb index 33ef0f60757..376c1979dd6 100644 --- a/app/models/voucher.rb +++ b/app/models/voucher.rb @@ -8,7 +8,6 @@ class Voucher < ApplicationRecord has_many :adjustments, as: :originator, class_name: 'Spree::Adjustment', - inverse_of: :voucher, dependent: :nullify validates :code, presence: true, uniqueness: { scope: :enterprise_id } diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index bbe7b8f2453..66d243fd590 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -11,14 +11,10 @@ module Spree it { is_expected.to have_one(:metadata) } it { is_expected.to have_many(:adjustments) } - it { is_expected.to belong_to(:adjustable) } - it { is_expected.to belong_to(:adjustable) } it { is_expected.to belong_to(:originator) } it { is_expected.to belong_to(:order) } it { is_expected.to belong_to(:tax_category) } - it { is_expected.to belong_to(:tax_rate) } - it { is_expected.to belong_to(:voucher) } end describe "scopes" do