From 8155e98d6146f6d2543b8f9b9f7c062fa928a9f1 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 ----- spec/models/spree/adjustment_spec.rb | 4 ---- 2 files changed, 9 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/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