From 4cb291290b543cc51539bb5925fa7bb690c44aea Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 3 Jul 2023 15:08:00 +0100 Subject: [PATCH] Update product factory --- spec/factories/product_factory.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/factories/product_factory.rb b/spec/factories/product_factory.rb index 7171f18351..f09e46bb96 100644 --- a/spec/factories/product_factory.rb +++ b/spec/factories/product_factory.rb @@ -28,10 +28,13 @@ FactoryBot.define do on_hand { 5 } end - tax_category { |r| Spree::TaxCategory.first || r.association(:tax_category) } + transient do + tax_category { |r| Spree::TaxCategory.first || r.association(:tax_category) } + end after(:create) do |product, evaluator| product.variants.first.on_hand = evaluator.on_hand + product.variants.first.tax_category = evaluator.tax_category product.reload end end @@ -63,15 +66,14 @@ FactoryBot.define do tax_rate_name { "" } included_in_price { "" } zone { nil } + tax_category { create(:tax_category) } end - tax_category { create(:tax_category) } - - after(:create) do |product, proxy| + after(:create) do |_product, proxy| raise "taxed_product factory requires a zone" unless proxy.zone create(:tax_rate, amount: proxy.tax_rate_amount, - tax_category: product.tax_category, + tax_category: proxy.tax_category, included_in_price: proxy.included_in_price, calculator: Calculator::DefaultTax.new, zone: proxy.zone,