mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Fix factory issues
This commit is contained in:
committed by
Gaetan Craig-Riou
parent
3b715875ad
commit
cd601319f3
@@ -3,13 +3,18 @@
|
||||
FactoryBot.define do
|
||||
factory :base_product, class: Spree::Product do
|
||||
sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" }
|
||||
|
||||
transient do
|
||||
primary_taxon { nil }
|
||||
end
|
||||
|
||||
primary_taxon_id { |p| (p.primary_taxon || Spree::Taxon.first || create(:taxon)).id }
|
||||
description { generate(:random_description) }
|
||||
price { 19.99 }
|
||||
sku { 'ABC' }
|
||||
deleted_at { nil }
|
||||
|
||||
supplier { Enterprise.is_primary_producer.first || FactoryBot.create(:supplier_enterprise) }
|
||||
primary_taxon { Spree::Taxon.first || FactoryBot.create(:taxon) }
|
||||
|
||||
unit_value { 1 }
|
||||
unit_description { '' }
|
||||
@@ -48,6 +53,7 @@ FactoryBot.define do
|
||||
on_demand { false }
|
||||
on_hand { 5 }
|
||||
end
|
||||
|
||||
after(:create) do |product, evaluator|
|
||||
product.variants.first.on_demand = evaluator.on_demand
|
||||
product.variants.first.on_hand = evaluator.on_hand
|
||||
|
||||
@@ -11,7 +11,8 @@ FactoryBot.define do
|
||||
width { generate(:random_float) }
|
||||
depth { generate(:random_float) }
|
||||
|
||||
product { |p| p.association(:base_product) }
|
||||
primary_taxon { Spree::Taxon.first || FactoryBot.create(:taxon) }
|
||||
product { |v| create(:product, primary_taxon_id: v.primary_taxon.id) }
|
||||
|
||||
# ensure stock item will be created for this variant
|
||||
before(:create) { create(:stock_location) if Spree::StockLocation.count.zero? }
|
||||
@@ -22,7 +23,7 @@ FactoryBot.define do
|
||||
on_hand { 5 }
|
||||
end
|
||||
|
||||
product { |p| p.association(:product) }
|
||||
product { |v| create(:product, primary_taxon_id: v.primary_taxon.id) }
|
||||
unit_value { 1 }
|
||||
unit_description { '' }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user