Remove shipping method from product distribution in factory.

This commit is contained in:
Rohan Mitchell
2013-08-12 14:21:39 +10:00
parent af6b16ecc4
commit f1485bf9c5
4 changed files with 7 additions and 21 deletions

View File

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

View File

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

View File

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

View File

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