diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb index e64de7426a2..a31d35558f7 100644 --- a/core/app/models/spree/shipment.rb +++ b/core/app/models/spree/shipment.rb @@ -95,6 +95,7 @@ def can_transition_from_canceled_to_ready? def add_shipping_method(shipping_method, selected = false) shipping_rates.create(shipping_method: shipping_method, selected: selected, cost: cost) end + deprecate :add_shipping_method, deprecator: Spree::Deprecation def after_cancel manifest.each { |item| manifest_restock(item) } diff --git a/core/lib/spree/testing_support/factories/shipment_factory.rb b/core/lib/spree/testing_support/factories/shipment_factory.rb index d8d4f8026e7..eb6508e3626 100644 --- a/core/lib/spree/testing_support/factories/shipment_factory.rb +++ b/core/lib/spree/testing_support/factories/shipment_factory.rb @@ -16,7 +16,11 @@ after(:create) do |shipment, evaluator| shipping_method = evaluator.shipping_method || create(:shipping_method, cost: evaluator.cost) - shipment.add_shipping_method(shipping_method, true) + shipment.shipping_rates.create!( + shipping_method: shipping_method, + cost: evaluator.cost, + selected: true + ) shipment.order.line_items.each do |line_item| line_item.quantity.times do diff --git a/core/spec/models/spree/shipment_spec.rb b/core/spec/models/spree/shipment_spec.rb index 151027489b4..d3cbbe9abca 100644 --- a/core/spec/models/spree/shipment_spec.rb +++ b/core/spec/models/spree/shipment_spec.rb @@ -797,7 +797,7 @@ describe '#selected_shipping_rate_id=' do let!(:air_shipping_method) { create(:shipping_method, name: "Air") } - let(:new_rate) { shipment.add_shipping_method(air_shipping_method) } + let(:new_rate) { shipment.shipping_rates.create!(shipping_method: air_shipping_method) } context 'when the id exists' do it 'sets the new shipping rate as selected' do