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 committed May 5, 2023
1 parent c4dde06 commit 8155e98
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 9 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
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 8155e98

Please sign in to comment.