Skip to content

Commit

Permalink
Remove non need belongs_to associations from Adjustments
Browse files Browse the repository at this point in the history
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: thoughtbot/shoulda-matchers#981
  • Loading branch information
rioug authored and dacook committed May 10, 2023
1 parent e8c71c8 commit b7abe29
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 10 deletions.
5 changes: 0 additions & 5 deletions app/models/spree/adjustment.rb
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion app/models/voucher.rb
Expand Up @@ -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 }
Expand Down
4 changes: 0 additions & 4 deletions spec/models/spree/adjustment_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit b7abe29

Please sign in to comment.