mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Fixes:
2) Spree::Classification won't destroy if classification is the primary taxon
(Used from /home/runner/work/openfoodnetwork/openfoodnetwork/spec/models/enterprise_group_spec.rb:43:in `block (3 levels) in <top (required)>')
Failure/Error: expect(classification.destroy).to be false
22 lines
646 B
Ruby
22 lines
646 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
class Classification < ActiveRecord::Base
|
|
self.table_name = 'spree_products_taxons'
|
|
belongs_to :product, class_name: "Spree::Product", touch: true
|
|
belongs_to :taxon, class_name: "Spree::Taxon", touch: true
|
|
|
|
before_destroy :dont_destroy_if_primary_taxon
|
|
|
|
private
|
|
|
|
def dont_destroy_if_primary_taxon
|
|
return unless product.primary_taxon == taxon
|
|
|
|
errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name,
|
|
product: product.name)
|
|
throw :abort
|
|
end
|
|
end
|
|
end
|