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
This commit is contained in:
Gaetan Craig-Riou
2023-05-05 13:12:59 +10:00
committed by Maikel Linke
parent b67f5ae154
commit d29119f5c5
3 changed files with 0 additions and 10 deletions

View File

@@ -42,11 +42,6 @@ module Spree
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

View File

@@ -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 }

View File

@@ -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