mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Fix Rubocop issue: Do not delete addresses having shipments
The reasoning is that we should not delete an address that has ever received a shipment
This commit is contained in:
@@ -12,7 +12,7 @@ module Spree
|
||||
belongs_to :state, class_name: "Spree::State", optional: true
|
||||
|
||||
has_one :enterprise, dependent: :restrict_with_exception
|
||||
has_many :shipments
|
||||
has_many :shipments, dependent: :restrict_with_exception
|
||||
|
||||
validates :address1, :city, :phone, presence: true
|
||||
validates :company, presence: true, unless: -> { first_name.blank? || last_name.blank? }
|
||||
|
||||
@@ -134,6 +134,17 @@ describe Spree::Address do
|
||||
end
|
||||
end
|
||||
|
||||
context "associations" do
|
||||
it "destroys shipments upon destroy" do
|
||||
address = create(:address)
|
||||
create(:shipment, address:)
|
||||
|
||||
expect {
|
||||
address.destroy
|
||||
}.to raise_error(ActiveRecord::DeleteRestrictionError)
|
||||
end
|
||||
end
|
||||
|
||||
context ".default" do
|
||||
it "sets up a new record the default country" do
|
||||
expect(Spree::Address.default.country).to eq DefaultCountry.country
|
||||
|
||||
Reference in New Issue
Block a user