Skip to content

Commit 12a5ebe

Browse files
committed
Add autosave: true to Shipping Rate taxes
Shipping Rate taxes are something we want to be able to modify in the order updater without having to update the order graph one by one.
1 parent a2f0ceb commit 12a5ebe

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

core/app/models/spree/shipping_rate.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class ShippingRate < Spree::Base
1212
class_name: "Spree::ShippingRateTax",
1313
foreign_key: "shipping_rate_id",
1414
inverse_of: :shipping_rate,
15-
dependent: :destroy
15+
dependent: :destroy,
16+
autosave: true
1617

1718
delegate :order, :currency, to: :shipment
1819
delegate :name, :tax_category, :tax_category_id, to: :shipping_method

core/spec/models/spree/shipping_rate_tax_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,19 @@ module Spree
7575
end
7676
end
7777
end
78+
79+
describe "autosaving when order is saved" do
80+
let(:tax_rate) { create(:tax_rate) }
81+
let(:shipping_rate) { create(:shipping_rate) }
82+
let(:shipment) { shipping_rate.shipment }
83+
84+
it "works" do
85+
shipping_rate.taxes.new(
86+
amount: -2,
87+
tax_rate: tax_rate
88+
)
89+
expect { shipment.save! }.to change { Spree::ShippingRateTax.count }
90+
end
91+
end
7892
end
7993
end

0 commit comments

Comments
 (0)