diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index c9ca6ca063..68437005e8 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -34,8 +34,8 @@ module Spree searchable_scopes :active, :with_properties belongs_to :shipping_category, class_name: 'Spree::ShippingCategory' - belongs_to :supplier, class_name: 'Enterprise', touch: true - belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true + belongs_to :supplier, class_name: 'Enterprise', optional: false, touch: true + belongs_to :primary_taxon, class_name: 'Spree::Taxon', optional: false, touch: true has_one :image, class_name: "Spree::Image", as: :viewable, dependent: :destroy @@ -54,9 +54,6 @@ module Spree validates :name, presence: true validates :shipping_category, presence: true - validates :supplier, presence: true - validates :primary_taxon, presence: true - validates :variant_unit, presence: true validates :unit_value, presence: { if: ->(p) { %w(weight volume).include?(p.variant_unit) && new_record? } } diff --git a/config/application.rb b/config/application.rb index 3f01f13856..0d2ae298fc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -227,7 +227,6 @@ module Openfoodnetwork # https://guides.rubyonrails.org/configuring.html#results-of-config-load-defaults config.load_defaults 6.1 config.action_view.form_with_generates_remote_forms = false - config.active_record.belongs_to_required_by_default = false config.active_record.cache_versioning = false config.active_record.has_many_inversing = false config.active_record.yaml_column_permitted_classes = [BigDecimal, Symbol] diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 5482d03024..f8e0388c67 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -11,10 +11,10 @@ module Spree it { is_expected.to have_one(:metadata) } it { is_expected.to have_many(:adjustments) } - it { is_expected.to belong_to(:adjustable) } - it { is_expected.to belong_to(:originator) } - it { is_expected.to belong_to(:order) } - it { is_expected.to belong_to(:tax_category) } + it { is_expected.to belong_to(:adjustable).optional } + it { is_expected.to belong_to(:originator).optional } + it { is_expected.to belong_to(:order).optional } + it { is_expected.to belong_to(:tax_category).optional } end describe "scopes" do diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index dc2be5b509..d99fe291f9 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -154,8 +154,8 @@ module Spree end describe "associations" do - it { is_expected.to belong_to(:supplier) } - it { is_expected.to belong_to(:primary_taxon) } + it { is_expected.to belong_to(:supplier).required } + it { is_expected.to belong_to(:primary_taxon).required } end describe "validations and defaults" do diff --git a/spec/models/subscription_spec.rb b/spec/models/subscription_spec.rb index 06fee1dfcb..742e1952f1 100644 --- a/spec/models/subscription_spec.rb +++ b/spec/models/subscription_spec.rb @@ -4,13 +4,13 @@ require 'spec_helper' describe Subscription, type: :model do describe "associations" do - it { expect(subject).to belong_to(:shop) } - it { expect(subject).to belong_to(:customer) } - it { expect(subject).to belong_to(:schedule) } - it { expect(subject).to belong_to(:shipping_method) } - it { expect(subject).to belong_to(:payment_method) } - it { expect(subject).to belong_to(:ship_address) } - it { expect(subject).to belong_to(:bill_address) } + it { expect(subject).to belong_to(:shop).optional } + it { expect(subject).to belong_to(:customer).optional } + it { expect(subject).to belong_to(:schedule).optional } + it { expect(subject).to belong_to(:shipping_method).optional } + it { expect(subject).to belong_to(:payment_method).optional } + it { expect(subject).to belong_to(:ship_address).optional } + it { expect(subject).to belong_to(:bill_address).optional } it { expect(subject).to have_many(:subscription_line_items) } it { expect(subject).to have_many(:order_cycles) } it { expect(subject).to have_many(:proxy_orders) }