Skip to content

Commit

Permalink
Merge pull request #3165 from CandleScience/carton-paranoia
Browse files Browse the repository at this point in the history
Ensure cartons find soft deleted shipping methods
  • Loading branch information
kennyadsl authored Oct 30, 2019
2 parents 6036639 + ee4c286 commit 458ef40
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 458ef40

Please sign in to comment.