Add missing associations and validations specs

This commit is contained in:
Gaetan Craig-Riou
2024-02-27 13:41:03 +11:00
parent 8abea0afcf
commit 22f4ae115a
2 changed files with 23 additions and 3 deletions

View File

@@ -25,7 +25,7 @@ module Spree
variants_display_name
supplier_name).join('_or_')}_cont".freeze
belongs_to :product, -> { with_deleted }, touch: true, class_name: 'Spree::Product'
belongs_to :product, -> { with_deleted }, required: true, touch: true, class_name: 'Spree::Product'
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', optional: false
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true, optional: false

View File

@@ -7,9 +7,29 @@ RSpec.describe Spree::Variant do
subject(:variant) { build(:variant) }
it { is_expected.to have_many :semantic_links }
it { is_expected.to belong_to(:product).required }
it { is_expected.to belong_to(:supplier).required }
it { is_expected.to have_many(:supplier_properties) }
# TODO add test for the other associations
it { is_expected.to have_many(:inventory_units) }
it { is_expected.to have_many(:line_items) }
it { is_expected.to have_many(:stock_items) }
it { is_expected.to have_many(:stock_locations).through(:stock_items) }
it { is_expected.to have_many(:images) }
it { is_expected.to have_one(:default_price) }
it { is_expected.to have_many(:prices) }
it { is_expected.to have_many(:exchange_variants) }
it { is_expected.to have_many(:exchanges).through(:exchange_variants) }
it { is_expected.to have_many(:variant_overrides) }
it { is_expected.to have_many(:inventory_items) }
it { is_expected.to have_many(:supplier_properties).through(:supplier) }
describe "shipping category" do
it "sets a shipping category if none provided" do
variant = build(:variant, shipping_category: nil)
expect(variant).to be_valid
expect(variant.shipping_category).to_not be_nil
end
end
describe "supplier properties" do
subject { create(:variant) }