mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Fix Rubocop: Delete dependent stock_movements
This commit is contained in:
@@ -565,17 +565,6 @@ RSpecRails/InferredSpecType:
|
||||
- 'spec/requests/voucher_adjustments_spec.rb'
|
||||
- 'spec/routing/stripe_spec.rb'
|
||||
|
||||
# Offense count: 11
|
||||
# Configuration parameters: Include.
|
||||
# Include: app/models/**/*.rb
|
||||
Rails/HasManyOrHasOneDependent:
|
||||
Exclude:
|
||||
- 'app/models/enterprise.rb'
|
||||
- 'app/models/spree/address.rb'
|
||||
- 'app/models/spree/stock_item.rb'
|
||||
- 'app/models/spree/tax_rate.rb'
|
||||
- 'app/models/spree/variant.rb'
|
||||
|
||||
# Offense count: 22
|
||||
# Configuration parameters: IgnoreScopes, Include.
|
||||
# Include: app/models/**/*.rb
|
||||
|
||||
@@ -8,7 +8,7 @@ module Spree
|
||||
|
||||
belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :stock_items
|
||||
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
||||
has_many :stock_movements, dependent: nil
|
||||
has_many :stock_movements, dependent: :destroy
|
||||
|
||||
validates :stock_location, :variant, presence: true
|
||||
validates :variant_id, uniqueness: { scope: [:stock_location_id, :deleted_at] }
|
||||
|
||||
@@ -14,10 +14,6 @@ module Spree
|
||||
|
||||
scope :recent, -> { order('created_at DESC') }
|
||||
|
||||
def readonly?
|
||||
!new_record?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_stock_item_quantity
|
||||
|
||||
@@ -109,12 +109,8 @@ RSpec.describe Spree::StockItem do
|
||||
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
|
||||
|
||||
it "does not destroy stock_movements when destroyed" do
|
||||
expect { subject.destroy }.not_to change { Spree::StockMovement.count }
|
||||
expect { subject.destroy }.to change { Spree::StockMovement.count }.by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,13 +11,6 @@ describe Spree::StockMovement do
|
||||
expect(subject).to respond_to(:stock_item)
|
||||
end
|
||||
|
||||
it 'is readonly unless new' do
|
||||
subject.save
|
||||
expect {
|
||||
subject.save
|
||||
}.to raise_error(ActiveRecord::ReadOnlyRecord)
|
||||
end
|
||||
|
||||
context "when quantity is negative" do
|
||||
context "after save" do
|
||||
it "should decrement the stock item count on hand" do
|
||||
|
||||
Reference in New Issue
Block a user