Skip to content

Commit

Permalink
Ensure cartons find soft deleted shipping methods
Browse files Browse the repository at this point in the history
Even if a shipping method is soft deleted, cartons should still be able to find it. If they can't, the #tracking_url method blows up when it tries to call #build_tracking_url on a nil shipping method.
  • Loading branch information
pelargir committed Oct 22, 2019
1 parent 0d658a3 commit ee4c286
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/carton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Spree::Carton < Spree::Base
belongs_to :address, class_name: 'Spree::Address', optional: true
belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :cartons, optional: true
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :cartons, optional: true
belongs_to :shipping_method, -> { with_discarded }, class_name: 'Spree::ShippingMethod', inverse_of: :cartons, optional: true

has_many :inventory_units, class_name: "Spree::InventoryUnit", inverse_of: :carton, dependent: :nullify
has_many :orders, -> { distinct }, through: :inventory_units
Expand Down
8 changes: 8 additions & 0 deletions core/spec/models/spree/carton_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
RSpec.describe Spree::Carton do
let(:carton) { create(:carton) }

describe 'shipping method' do
it 'returns soft deleted shipping method' do
carton = create(:carton)
carton.shipping_method.discard
expect(carton.reload.shipping_method).to be_present
end
end

describe "#create" do
subject { carton }

Expand Down

0 comments on commit ee4c286

Please sign in to comment.