Extract orders factories to separate file

This commit is contained in:
luisramos0
2019-06-14 12:17:24 +01:00
parent 91fcb7c7c4
commit 06e3328ce2
2 changed files with 85 additions and 83 deletions

View File

@@ -109,64 +109,6 @@ FactoryBot.define do
after(:create) { |c| c.set_preference(:per_kg, 0.5); c.save! }
end
factory :order_with_totals_and_distribution, parent: :order_with_distributor do
transient do
shipping_fee 3
end
order_cycle { create(:simple_order_cycle) }
after(:create) do |order, proxy|
product = create(:simple_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
distributor { create(:distributor_enterprise) }
end
factory :order_with_taxes, parent: :completed_order_with_totals do
transient do
product_price 0
tax_rate_amount 0
tax_rate_name ""
end
distributor { create(:distributor_enterprise) }
order_cycle { create(:simple_order_cycle) }
after(:create) do |order, proxy|
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)
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)}
order_cycle { create(:simple_order_cycle) }
after(:create) do |order|
create(:payment, amount: order.total + 10000, order: order, state: "completed")
order.reload
end
end
factory :order_without_full_payment, parent: :completed_order_with_totals do
distributor { create(:distributor_enterprise)}
order_cycle { create(:simple_order_cycle) }
after(:create) do |order|
create(:payment, amount: order.total - 1, order: order, state: "completed")
order.reload
end
end
factory :shipping_method_with, parent: :shipping_method do
trait :delivery do
require_ship_address { true }
@@ -228,31 +170,6 @@ FactoryBot.define do
end
end
factory :completed_order_with_fees, parent: :order_with_distributor do
transient do
payment_fee 5
shipping_fee 3
end
ship_address { create(:address) }
order_cycle { create(:simple_order_cycle) }
after(:create) do |order, evaluator|
create(:line_item, order: order)
product = create(:simple_product)
create(:line_item, order: order, product: product)
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(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee, distributors: [order.distributor])
order.reload
while !order.completed? do break unless order.next! end
end
end
factory :line_item_with_shipment, parent: :line_item do
transient do
shipping_fee 3

View File

@@ -1,3 +1,88 @@
FactoryBot.define do
factory :order_with_totals_and_distribution, parent: :order_with_distributor do
transient do
shipping_fee 3
end
order_cycle { create(:simple_order_cycle) }
after(:create) do |order, proxy|
product = create(:simple_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
distributor { create(:distributor_enterprise) }
end
factory :order_with_taxes, parent: :completed_order_with_totals do
transient do
product_price 0
tax_rate_amount 0
tax_rate_name ""
end
distributor { create(:distributor_enterprise) }
order_cycle { create(:simple_order_cycle) }
after(:create) do |order, proxy|
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)
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)}
order_cycle { create(:simple_order_cycle) }
after(:create) do |order|
create(:payment, amount: order.total + 10000, order: order, state: "completed")
order.reload
end
end
factory :order_without_full_payment, parent: :completed_order_with_totals do
distributor { create(:distributor_enterprise)}
order_cycle { create(:simple_order_cycle) }
after(:create) do |order|
create(:payment, amount: order.total - 1, order: order, state: "completed")
order.reload
end
end
factory :completed_order_with_fees, parent: :order_with_distributor do
transient do
payment_fee 5
shipping_fee 3
end
ship_address { create(:address) }
order_cycle { create(:simple_order_cycle) }
after(:create) do |order, evaluator|
create(:line_item, order: order)
product = create(:simple_product)
create(:line_item, order: order, product: product)
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(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee, distributors: [order.distributor])
order.reload
while !order.completed? do break unless order.next! end
end
end
end
FactoryBot.modify do
factory :order do
trait :with_line_item do