From 0377e02dc101aea7f3960571b3a273b791787efb Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Thu, 1 Aug 2019 00:50:14 +0800 Subject: [PATCH] Add specs testing that shipments see deleted variants --- spec/models/spree/shipment_spec.rb | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 spec/models/spree/shipment_spec.rb diff --git a/spec/models/spree/shipment_spec.rb b/spec/models/spree/shipment_spec.rb new file mode 100644 index 0000000000..b37dd498ff --- /dev/null +++ b/spec/models/spree/shipment_spec.rb @@ -0,0 +1,33 @@ +require "spec_helper" + +describe Spree::Shipment do + describe "manifest" do + let!(:product) { create(:product) } + let!(:order) { create(:order, distributor: product.supplier) } + let!(:deleted_variant) { create(:variant, product: product) } + let!(:other_variant) { create(:variant, product: product) } + let!(:line_item_for_deleted) { create(:line_item, order: order, variant: deleted_variant) } + let!(:line_item_for_other) { create(:line_item, order: order, variant: other_variant) } + let!(:shipment) { create(:shipment_with, :shipping_method, order: order) } + + context "when the variant is soft-deleted" do + before { deleted_variant.delete } + + it "can still access the variant" do + shipment.reload + variants = shipment.manifest.map(&:variant).uniq + expect(variants.sort_by(&:id)).to eq([deleted_variant, other_variant].sort_by(&:id)) + end + end + + context "when the product is soft-deleted" do + before { deleted_variant.product.delete } + + it "can still access the variant" do + shipment.reload + variants = shipment.manifest.map(&:variant) + expect(variants.sort_by(&:id)).to eq([deleted_variant, other_variant].sort_by(&:id)) + end + end + end +end