From f1485bf9c5402fa3e2b9705cbac1cf9aaf31b5f6 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Mon, 12 Aug 2013 14:21:39 +1000 Subject: [PATCH] Remove shipping method from product distribution in factory. --- spec/factories.rb | 14 -------------- spec/features/admin/enterprise_fees_spec.rb | 2 +- spec/features/admin/reports_spec.rb | 2 +- spec/support/spree/init.rb | 10 +++++----- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index 5d288a1993..b652afd596 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/features/admin/enterprise_fees_spec.rb b/spec/features/admin/enterprise_fees_spec.rb index 745f953bca..2f3c9e64fd 100644 --- a/spec/features/admin/enterprise_fees_spec.rb +++ b/spec/features/admin/enterprise_fees_spec.rb @@ -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' diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 1202f7da45..7345a527b0 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -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) diff --git a/spec/support/spree/init.rb b/spec/support/spree/init.rb index 471b7cf2c9..c60c7bc0d4 100644 --- a/spec/support/spree/init.rb +++ b/spec/support/spree/init.rb @@ -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