Skip to content

Commit

Permalink
Merge pull request #1627 from CasperSleep/cascade_shipment_destroy_sh…
Browse files Browse the repository at this point in the history
…ipping_rate_taxes

delete spree_shipping_rate_taxes when a shipment is destroyed
  • Loading branch information
jhawthorn authored Dec 1, 2016
2 parents 0ba3f0d + f9801af commit d06cfea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Shipment < Spree::Base

has_many :adjustments, as: :adjustable, inverse_of: :adjustable, dependent: :delete_all
has_many :inventory_units, dependent: :destroy, inverse_of: :shipment
has_many :shipping_rates, -> { order(:cost) }, dependent: :delete_all
has_many :shipping_rates, -> { order(:cost) }, dependent: :destroy
has_many :shipping_methods, through: :shipping_rates
has_many :state_changes, as: :stateful
has_many :cartons, -> { uniq }, through: :inventory_units
Expand Down
18 changes: 15 additions & 3 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,21 @@

# Regression test for https://github.com/spree/spree/issues/3349
context "#destroy" do
it "destroys linked shipping_rates" do
reflection = Spree::Shipment.reflect_on_association(:shipping_rates)
expect(reflection.options[:dependent]).to be(:delete_all)
let(:shipping_rate) do
Spree::ShippingRate.create!(
shipping_method: shipping_method,
selected: true,
taxes: [Spree::ShippingRateTax.new(amount: 20)]
)
end
it "destroys linked shipping_rates and shipping_rate_taxes" do
shipping_rate = shipment.shipping_rates.first
shipping_rate_tax = shipping_rate.taxes.first

shipment.destroy

expect{shipping_rate.reload}.to raise_error(ActiveRecord::RecordNotFound)
expect{shipping_rate_tax.reload}.to raise_error(ActiveRecord::RecordNotFound)
end
end

Expand Down

0 comments on commit d06cfea

Please sign in to comment.