Fix sample product creation and use bang methods

Mistakes like the missing fee when creating product distributions were
hidden, because I didn't use the bang methods to create records.
This commit is contained in:
Maikel Linke
2019-01-08 15:39:53 +11:00
parent 1d07327325
commit c3029c612a
3 changed files with 13 additions and 10 deletions

View File

@@ -15,7 +15,7 @@ module Addressing
def zone
zone = Spree::Zone.find_or_create_by_name!("Australia")
zone.members.create(zonable: country)
zone.members.create!(zonable: country)
zone
end

View File

@@ -18,7 +18,7 @@ class InventoryFactory
enterprise: shop,
variant: product.variants.first,
visible: true
).find_or_create_by_variant_id(product.variants.first.id)
).find_or_create_by_variant_id!(product.variants.first.id)
create_override(shop, product)
end
@@ -29,6 +29,6 @@ class InventoryFactory
price: 12,
on_demand: false,
count_on_hand: 5
).find_or_create_by_variant_id(product.variants.first.id)
).find_or_create_by_variant_id!(product.variants.first.id)
end
end

View File

@@ -76,15 +76,18 @@ class ProductFactory
unit_value: 1,
on_demand: true
)
create_product_with_distribution(params)
create_product_with_distribution(params, hash[:supplier])
end
def create_product_with_distribution(params)
product = Spree::Product.create_with(params).find_or_create_by_name(params[:name])
ProductDistribution.create(
product: product,
distributor: params[:distributor]
)
def create_product_with_distribution(params, supplier)
product = Spree::Product.create_with(params).find_or_create_by_name!(params[:name])
distribution_params = {
distributor_id: params[:distributor].id,
enterprise_fee_id: supplier.enterprise_fees.first.id
}
ProductDistribution.create_with(distribution_params).find_or_create_by_product_id!(product.id)
product
end
end