diff --git a/spec/factories/calculator_factory.rb b/spec/factories/calculator_factory.rb index 5cbe8ee182..25dd9b0a13 100644 --- a/spec/factories/calculator_factory.rb +++ b/spec/factories/calculator_factory.rb @@ -7,5 +7,5 @@ FactoryBot.define do factory :weight_calculator, class: Calculator::Weight do after(:build) { |c| c.set_preference(:per_kg, 0.5) } after(:create) { |c| c.set_preference(:per_kg, 0.5); c.save! } - end + end end diff --git a/spec/factories/enterprise_factory.rb b/spec/factories/enterprise_factory.rb index aaf068082e..ea93a818aa 100644 --- a/spec/factories/enterprise_factory.rb +++ b/spec/factories/enterprise_factory.rb @@ -8,12 +8,12 @@ FactoryBot.define do address { FactoryBot.create(:address) } end - factory :supplier_enterprise, :parent => :enterprise do + factory :supplier_enterprise, parent: :enterprise do is_primary_producer true sells "none" end - factory :distributor_enterprise, :parent => :enterprise do + factory :distributor_enterprise, parent: :enterprise do is_primary_producer false sells "any" @@ -33,4 +33,4 @@ FactoryBot.define do charges_sales_tax { true } allow_order_changes { true } end -end \ No newline at end of file +end diff --git a/spec/factories/order_factory.rb b/spec/factories/order_factory.rb index f6f03f5d2f..bab9767ca0 100644 --- a/spec/factories/order_factory.rb +++ b/spec/factories/order_factory.rb @@ -8,12 +8,14 @@ FactoryBot.define do after(:create) do |order, proxy| product = create(:simple_product) - create(:line_item_with_shipment, shipping_fee: proxy.shipping_fee, order: order, product: product) + create(:line_item_with_shipment, shipping_fee: proxy.shipping_fee, + order: order, + product: product) order.reload end end - factory :order_with_distributor, :parent => :order do + factory :order_with_distributor, parent: :order do distributor { create(:distributor_enterprise) } end @@ -31,24 +33,27 @@ FactoryBot.define do order.distributor.update_attribute(:charges_sales_tax, true) Spree::Zone.global.update_attribute(:default_tax, true) - p = FactoryBot.create(:taxed_product, zone: Spree::Zone.global, price: proxy.product_price, tax_rate_amount: proxy.tax_rate_amount, tax_rate_name: proxy.tax_rate_name) + p = FactoryBot.create(:taxed_product, zone: Spree::Zone.global, + price: proxy.product_price, + tax_rate_amount: proxy.tax_rate_amount, + tax_rate_name: proxy.tax_rate_name) FactoryBot.create(:line_item, order: order, product: p, price: p.price) order.reload end end factory :order_with_credit_payment, parent: :completed_order_with_totals do - distributor { create(:distributor_enterprise)} + distributor { create(:distributor_enterprise) } order_cycle { create(:simple_order_cycle) } after(:create) do |order| - create(:payment, amount: order.total + 10000, order: order, state: "completed") + create(:payment, amount: order.total + 10_000, order: order, state: "completed") order.reload end end factory :order_without_full_payment, parent: :completed_order_with_totals do - distributor { create(:distributor_enterprise)} + distributor { create(:distributor_enterprise) } order_cycle { create(:simple_order_cycle) } after(:create) do |order| @@ -73,9 +78,13 @@ FactoryBot.define do payment_calculator = build(:calculator_per_item, preferred_amount: evaluator.payment_fee) payment_method = create(:payment_method, calculator: payment_calculator) - create(:payment, order: order, amount: order.total, payment_method: payment_method, state: 'checkout') + create(:payment, order: order, + amount: order.total, + payment_method: payment_method, + state: 'checkout') - create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee, distributors: [order.distributor]) + create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee, + distributors: [order.distributor]) order.reload while !order.completed? do break unless order.next! end diff --git a/spec/factories/product_factory.rb b/spec/factories/product_factory.rb index f4f6e12e7d..9c97b92f7b 100644 --- a/spec/factories/product_factory.rb +++ b/spec/factories/product_factory.rb @@ -2,7 +2,9 @@ FactoryBot.define do factory :product_with_image, parent: :product do after(:create) do |product| image = File.open(Rails.root.join('app', 'assets', 'images', 'logo-white.png')) - Spree::Image.create(attachment: image, viewable_id: product.master.id, viewable_type: 'Spree::Variant') + Spree::Image.create(attachment: image, + viewable_id: product.master.id, + viewable_type: 'Spree::Variant') end end @@ -18,8 +20,8 @@ FactoryBot.define do product.variants.first.on_hand = evaluator.on_hand end end - - factory :taxed_product, :parent => :product do + + factory :taxed_product, parent: :product do transient do tax_rate_amount 0 tax_rate_name "" @@ -30,7 +32,12 @@ FactoryBot.define do 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, included_in_price: true, calculator: Spree::Calculator::DefaultTax.new, zone: proxy.zone, name: proxy.tax_rate_name) + create(:tax_rate, amount: proxy.tax_rate_amount, + tax_category: product.tax_category, + included_in_price: true, + calculator: Spree::Calculator::DefaultTax.new, + zone: proxy.zone, + name: proxy.tax_rate_name) end end end diff --git a/spec/factories/shipment_factory.rb b/spec/factories/shipment_factory.rb index dc361889ea..aa4002f9c6 100644 --- a/spec/factories/shipment_factory.rb +++ b/spec/factories/shipment_factory.rb @@ -13,11 +13,15 @@ FactoryBot.define do shipping_method { create(:shipping_method) } end - shipping_rates { [Spree::ShippingRate.create(shipping_method: shipping_method, selected: true)] } + shipping_rates { + [Spree::ShippingRate.create(shipping_method: shipping_method, selected: true)] + } - after(:create) do |shipment, evaluator| + after(:create) do |shipment, _evaluator| shipment.order.line_items.each do |line_item| - line_item.quantity.times { shipment.inventory_units.create(variant_id: line_item.variant_id) } + line_item.quantity.times { + shipment.inventory_units.create(variant_id: line_item.variant_id) + } end end end @@ -27,6 +31,6 @@ end FactoryBot.modify do factory :shipment, class: Spree::Shipment do # keeps test shipments unique per order - initialize_with { Spree::Shipment.find_or_create_by_order_id(order.id)} + initialize_with { Spree::Shipment.find_or_create_by_order_id(order.id) } end end diff --git a/spec/factories/shipping_method_factory.rb b/spec/factories/shipping_method_factory.rb index e37e7d28c6..4d4d7c710e 100644 --- a/spec/factories/shipping_method_factory.rb +++ b/spec/factories/shipping_method_factory.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :shipping_method_with, parent: :shipping_method do + factory :shipping_method_with, parent: :shipping_method do trait :delivery do require_ship_address { true } end diff --git a/spec/factories/subscription_factory.rb b/spec/factories/subscription_factory.rb index a7a4c0a4f2..009f9ef802 100644 --- a/spec/factories/subscription_factory.rb +++ b/spec/factories/subscription_factory.rb @@ -16,17 +16,27 @@ FactoryBot.define do after(:create) do |subscription, proxy| if proxy.with_items - subscription.subscription_line_items = build_list(:subscription_line_item, 3, subscription: subscription) + subscription.subscription_line_items = build_list(:subscription_line_item, + 3, + subscription: subscription) subscription.order_cycles.each do |oc| - ex = oc.exchanges.outgoing.find_by_sender_id_and_receiver_id(subscription.shop_id, subscription.shop_id) || - create(:exchange, :order_cycle => oc, :sender => subscription.shop, :receiver => subscription.shop, :incoming => false, :pickup_time => 'time', :pickup_instructions => 'instructions') + ex = oc.exchanges.outgoing.find_by_sender_id_and_receiver_id( + subscription.shop_id, subscription.shop_id + ) + ex ||= create(:exchange, order_cycle: oc, + sender: subscription.shop, + receiver: subscription.shop, + incoming: false, + pickup_time: 'time', + pickup_instructions: 'instructions') subscription.subscription_line_items.each { |sli| ex.variants << sli.variant } end end if proxy.with_proxy_orders subscription.order_cycles.each do |oc| - subscription.proxy_orders << create(:proxy_order, subscription: subscription, order_cycle: oc) + subscription.proxy_orders << create(:proxy_order, subscription: subscription, + order_cycle: oc) end end end @@ -37,4 +47,4 @@ FactoryBot.define do variant quantity 1 end -end \ No newline at end of file +end