mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-03 02:21:33 +00:00
Remove shipping method from product distribution in factory.
This commit is contained in:
@@ -89,7 +89,6 @@ FactoryGirl.define do
|
||||
factory :product_distribution, :class => ProductDistribution do
|
||||
product { |pd| Spree::Product.first || FactoryGirl.create(:product) }
|
||||
distributor { |pd| Enterprise.is_distributor.first || FactoryGirl.create(:distributor_enterprise) }
|
||||
shipping_method { |pd| Spree::ShippingMethod.where("name != 'Delivery'").first || FactoryGirl.create(:shipping_method) }
|
||||
enterprise_fee { |pd| FactoryGirl.create(:enterprise_fee, enterprise: pd.distributor) }
|
||||
end
|
||||
|
||||
@@ -135,19 +134,6 @@ FactoryGirl.modify do
|
||||
|
||||
supplier { Enterprise.is_primary_producer.first || FactoryGirl.create(:supplier_enterprise) }
|
||||
on_hand 3
|
||||
|
||||
# before(:create) do |product, evaluator|
|
||||
# product.product_distributions = [FactoryGirl.create(:product_distribution, :product => product)]
|
||||
# end
|
||||
|
||||
# Do not create products distributed via the 'Delivery' shipping method
|
||||
after(:create) do |product, evaluator|
|
||||
pd = product.product_distributions.first
|
||||
if pd.andand.shipping_method.andand.name == 'Delivery'
|
||||
pd.shipping_method = Spree::ShippingMethod.where("name != 'Delivery'").first || FactoryGirl.create(:shipping_method)
|
||||
pd.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
factory :shipping_method do
|
||||
|
||||
@@ -17,7 +17,7 @@ feature %q{
|
||||
end
|
||||
|
||||
scenario "listing enterprise fees" do
|
||||
fee = create(:enterprise_fee)
|
||||
fee = create(:enterprise_fee, name: '$0.50 / kg')
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Configuration'
|
||||
|
||||
@@ -54,7 +54,7 @@ feature %q{
|
||||
@distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
|
||||
@distributor = create(:distributor_enterprise, :address => @distributor_address)
|
||||
product = create(:product)
|
||||
product_distribution = create(:product_distribution, :product => product, :distributor => @distributor, :shipping_method => create(:shipping_method))
|
||||
product_distribution = create(:product_distribution, :product => product, :distributor => @distributor)
|
||||
@shipping_instructions = "pick up on thursday please!"
|
||||
@order1 = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions)
|
||||
@order2 = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# Initialise shipping method when created without one, like this:
|
||||
# Initialise enterprise fee when created without one, like this:
|
||||
# create(:product, :distributors => [...])
|
||||
# In this case, we don't care what the shipping method is, but we need one for validations to pass.
|
||||
# In this case, we don't care what the fee is, but we need one for validations to pass.
|
||||
ProductDistribution.class_eval do
|
||||
before_validation :init_shipping_method
|
||||
before_validation :init_enterprise_fee
|
||||
|
||||
def init_shipping_method
|
||||
self.shipping_method ||= Spree::ShippingMethod.first || FactoryGirl.create(:shipping_method)
|
||||
def init_enterprise_fee
|
||||
self.enterprise_fee ||= EnterpriseFee.where(enterprise_id: distributor).first || FactoryGirl.create(:enterprise_fee, enterprise_id: distributor)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user