Merge pull request #6617 from Matt-Yorkley/stock-items-variant-deletion

Stock items and variant deletion
This commit is contained in:
Andy Brett
2021-01-09 12:12:24 -08:00
committed by GitHub
3 changed files with 20 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ module Spree
belongs_to :stock_location, class_name: 'Spree::StockLocation'
belongs_to :variant, class_name: 'Spree::Variant'
has_many :stock_movements, dependent: :destroy
has_many :stock_movements
validates :stock_location, :variant, presence: true
validates :variant_id, uniqueness: { scope: [:stock_location_id, :deleted_at] }

View File

@@ -220,6 +220,17 @@ module Spree
end
end
context "has stock movements" do
let(:product) { create(:product) }
let(:variant) { product.master }
let(:stock_item) { variant.stock_items.first }
it "doesnt raise ReadOnlyRecord error" do
Spree::StockMovement.create!(stock_item: stock_item, quantity: 1)
expect { product.destroy }.not_to raise_error
end
end
describe "associations" do
it { is_expected.to belong_to(:supplier) }
it { is_expected.to belong_to(:primary_taxon) }

View File

@@ -102,5 +102,13 @@ RSpec.describe Spree::StockItem do
end
end
end
context "with stock movements" do
before { Spree::StockMovement.create(stock_item: subject, quantity: 1) }
it "doesnt raise ReadOnlyRecord error" do
expect { subject.destroy }.not_to raise_error
end
end
end
end