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:
luisramos0
2019-01-17 14:34:15 +00:00
parent 1d60732581
commit f896e78e6f
3 changed files with 18 additions and 8 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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