mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
Set StockLocation.backorderable_default to false in DefaultStockLocation and in StockLocation factory.
This makes the default value of variant.on_demand false in all environments and in tests. Additionally, adapt VariantStock.on_demand test and product factory to this change (setting on_hand value in product factory so it's not out of stock by default).
This commit is contained in:
@@ -6,7 +6,7 @@ class DefaultStockLocation
|
||||
def self.create!
|
||||
country = Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE'])
|
||||
state = country.states.first
|
||||
Spree::StockLocation.create!(name: NAME, country_id: country.id, state_id: state.id)
|
||||
Spree::StockLocation.create!(name: NAME, country_id: country.id, state_id: state.id, backorderable_default: false)
|
||||
end
|
||||
|
||||
def self.destroy_all
|
||||
|
||||
@@ -551,19 +551,26 @@ FactoryBot.define do
|
||||
on_hand { 5 }
|
||||
end
|
||||
after(:create) do |product, evaluator|
|
||||
product.variants.first.tap do |variant|
|
||||
variant.on_demand = evaluator.on_demand
|
||||
variant.count_on_hand = evaluator.on_hand
|
||||
variant.save
|
||||
end
|
||||
product.master.on_demand = evaluator.on_demand
|
||||
product.master.on_hand = evaluator.on_hand
|
||||
product.variants.first.on_demand = evaluator.on_demand
|
||||
product.variants.first.on_hand = evaluator.on_hand
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
FactoryBot.modify do
|
||||
factory :product do
|
||||
transient do
|
||||
on_hand { 5 }
|
||||
end
|
||||
|
||||
primary_taxon { Spree::Taxon.first || FactoryBot.create(:taxon) }
|
||||
|
||||
after(:create) do |product, evaluator|
|
||||
product.master.on_hand = evaluator.on_hand
|
||||
product.variants.first.on_hand = evaluator.on_hand
|
||||
end
|
||||
end
|
||||
|
||||
factory :base_product do
|
||||
@@ -661,6 +668,9 @@ FactoryBot.modify do
|
||||
|
||||
# Ensures the name attribute is not assigned after instantiating the default location
|
||||
transient { name 'default' }
|
||||
|
||||
# sets the default value for variant.on_demand
|
||||
backorderable_default false
|
||||
end
|
||||
|
||||
factory :shipment, class: Spree::Shipment do
|
||||
|
||||
@@ -135,7 +135,7 @@ describe VariantStock do
|
||||
let(:variant) { build(:variant) }
|
||||
|
||||
it 'returns stock location default' do
|
||||
expect(variant.on_demand).to be_truthy
|
||||
expect(variant.on_demand).to be_falsy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user