Fix more rubocop issues in spec/factories

This commit is contained in:
luisramos0
2019-06-14 13:42:27 +01:00
parent 59593c824a
commit 6efb71d903
7 changed files with 56 additions and 26 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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