From b5d324ec8c60dea04a6eeaa4babf3020cffa72a1 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 13 Aug 2013 07:16:13 +1000 Subject: [PATCH] Drop itemwise shipping method use in tests --- spec/factories.rb | 8 ---- ...distributor_info_rich_text_feature_spec.rb | 2 +- spec/features/consumer/add_to_cart_spec.rb | 18 ++++---- spec/features/consumer/checkout_spec.rb | 44 +++++++++---------- spec/support/spree/init.rb | 18 -------- 5 files changed, 31 insertions(+), 59 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index b652afd596..1cdf062e9b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -92,11 +92,6 @@ FactoryGirl.define do enterprise_fee { |pd| FactoryGirl.create(:enterprise_fee, enterprise: pd.distributor) } end - factory :itemwise_shipping_method, :parent => :shipping_method do - name 'Delivery' - calculator { FactoryGirl.build(:itemwise_calculator) } - end - factory :adjustment_metadata, :class => AdjustmentMetadata do adjustment { FactoryGirl.create(:adjustment) } enterprise { FactoryGirl.create(:distributor_enterprise) } @@ -105,9 +100,6 @@ FactoryGirl.define do enterprise_role 'distributor' end - factory :itemwise_calculator, :class => OpenFoodWeb::Calculator::Itemwise do - end - factory :weight_calculator, :class => OpenFoodWeb::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! } diff --git a/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb b/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb index ed56b57ed3..cd95945f8b 100644 --- a/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb +++ b/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb @@ -90,7 +90,7 @@ feature "enterprises distributor info as rich text" do zone = create(:zone) c = Spree::Country.find_by_name('Australia') Spree::ZoneMember.create(:zoneable => c, :zone => zone) - create(:itemwise_shipping_method, zone: zone) + create(:shipping_method, zone: zone) create(:payment_method, :description => 'Cheque payment method') end diff --git a/spec/features/consumer/add_to_cart_spec.rb b/spec/features/consumer/add_to_cart_spec.rb index c5e01c1efb..ffcc8c3e12 100644 --- a/spec/features/consumer/add_to_cart_spec.rb +++ b/spec/features/consumer/add_to_cart_spec.rb @@ -33,12 +33,12 @@ feature %q{ d2 = create(:distributor_enterprise) create(:product, :distributors => [d2]) p = create(:product, :price => 12.34) - create(:product_distribution, :product => p, :distributor => d1, :shipping_method => create(:shipping_method)) + create(:product_distribution, :product => p, :distributor => d1) - # ... with a flat rate shipping method of cost $1.23 - sm = p.product_distributions.first.shipping_method - sm.calculator.preferred_amount = 1.23 - sm.calculator.save! + # ... with a flat rate distribution fee of $1.23 + ef = p.product_distributions.first.enterprise_fee + ef.calculator = Spree::Calculator::FlatRate.new preferred_amount: 1.23 + ef.calculator.save! # When I choose a distributor visit spree.root_path @@ -51,15 +51,13 @@ feature %q{ # Then the correct totals should be displayed page.should have_selector 'span.item-total', :text => '$12.34' - page.should have_selector 'span.shipping-total', :text => '$1.23' + page.should have_selector 'span.distribution-total', :text => '$1.23' page.should have_selector 'span.grand-total', :text => '$13.57' - # And the item should be in my cart, with the distribution info set for the line item + # And the item should be in my cart order = Spree::Order.last line_item = order.line_items.first line_item.product.should == p - line_item.distribution_fee.should == 1.23 - line_item.shipping_method_name.should == p.product_distributions.first.shipping_method.name # And my order should have its distributor set to the chosen distributor order.distributor.should == d1 @@ -229,7 +227,7 @@ feature %q{ page.should have_selector 'span.item-total', :text => '$12.34' # TODO: Test these when order cycle fees is implemented - # page.should have_selector 'span.shipping-total', :text => '$1.23' + # page.should have_selector 'span.distribution-total', :text => '$1.23' # page.should have_selector 'span.grand-total', :text => '$13.57' # And the item should be in my cart diff --git a/spec/features/consumer/checkout_spec.rb b/spec/features/consumer/checkout_spec.rb index 9ed52a996f..8079e14748 100644 --- a/spec/features/consumer/checkout_spec.rb +++ b/spec/features/consumer/checkout_spec.rb @@ -37,26 +37,26 @@ feature %q{ :country => Spree::Country.find_by_name('Australia')), :pickup_times => 'Tuesday, 4 PM') - @shipping_method_1 = create(:shipping_method, :name => 'Shipping Method One') - @shipping_method_1.calculator.set_preference :amount, 1 - @shipping_method_1.calculator.save! + @enterprise_fee_1 = create(:enterprise_fee, :name => 'Shipping Method One', :calculator => Spree::Calculator::FlatRate.new) + @enterprise_fee_1.calculator.set_preference :amount, 1 + @enterprise_fee_1.calculator.save! - @shipping_method_2 = create(:shipping_method, :name => 'Shipping Method Two') - @shipping_method_2.calculator.set_preference :amount, 2 - @shipping_method_2.calculator.save! + @enterprise_fee_2 = create(:enterprise_fee, :name => 'Shipping Method Two', :calculator => Spree::Calculator::FlatRate.new) + @enterprise_fee_2.calculator.set_preference :amount, 2 + @enterprise_fee_2.calculator.save! @product_1 = create(:product, :name => 'Fuji apples') - @product_1.product_distributions.create(:distributor => @distributor, :shipping_method => @shipping_method_1) - @product_1.product_distributions.create(:distributor => @distributor_alternative, :shipping_method => @shipping_method_1) + @product_1.product_distributions.create(:distributor => @distributor, :enterprise_fee => @enterprise_fee_1) + @product_1.product_distributions.create(:distributor => @distributor_alternative, :enterprise_fee => @enterprise_fee_1) @product_2 = create(:product, :name => 'Garlic') - @product_2.product_distributions.create(:distributor => @distributor, :shipping_method => @shipping_method_2) - @product_2.product_distributions.create(:distributor => @distributor_alternative, :shipping_method => @shipping_method_2) + @product_2.product_distributions.create(:distributor => @distributor, :enterprise_fee => @enterprise_fee_2) + @product_2.product_distributions.create(:distributor => @distributor_alternative, :enterprise_fee => @enterprise_fee_2) @zone = create(:zone) c = Spree::Country.find_by_name('Australia') Spree::ZoneMember.create(:zoneable => c, :zone => @zone) - create(:itemwise_shipping_method, zone: @zone) + create(:shipping_method, zone: @zone) create(:payment_method, :description => 'Cheque payment method') end @@ -91,21 +91,21 @@ feature %q{ end scenario "changing distributor updates delivery fees" do - # Given two distributors and shipping methods + # Given two distributors and enterprise fees d1 = create(:distributor_enterprise) d2 = create(:distributor_enterprise) - sm1 = create(:shipping_method) - sm1.calculator.set_preference :amount, 1.23; sm1.calculator.save! - sm2 = create(:free_shipping_method) - sm2.calculator.set_preference :amount, 2.34; sm2.calculator.save! + ef1 = create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new) + ef1.calculator.set_preference :amount, 1.23; ef1.calculator.save! + ef2 = create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new) + ef2.calculator.set_preference :amount, 2.34; ef2.calculator.save! # And two products both available from both distributors p1 = create(:product) - create(:product_distribution, product: p1, distributor: d1, shipping_method: sm1) - create(:product_distribution, product: p1, distributor: d2, shipping_method: sm2) + create(:product_distribution, product: p1, distributor: d1, enterprise_fee: ef1) + create(:product_distribution, product: p1, distributor: d2, enterprise_fee: ef2) p2 = create(:product) - create(:product_distribution, product: p2, distributor: d1, shipping_method: sm1) - create(:product_distribution, product: p2, distributor: d2, shipping_method: sm2) + create(:product_distribution, product: p2, distributor: d1, enterprise_fee: ef1) + create(:product_distribution, product: p2, distributor: d2, enterprise_fee: ef2) # When I add the first product to my cart with the first distributor #visit spree.root_path @@ -115,7 +115,7 @@ feature %q{ click_button 'Add To Cart' # Then I should see shipping costs for the first distributor - page.should have_selector 'span.shipping-total', text: '$1.23' + page.should have_selector 'span.distribution-total', text: '$1.23' # When add the second with the second distributor click_link 'Continue shopping' @@ -124,7 +124,7 @@ feature %q{ click_button 'Add To Cart' # Then I should see shipping costs for the second distributor - page.should have_selector 'span.shipping-total', text: '$4.68' + page.should have_selector 'span.distribution-total', text: '$4.68' end scenario "adding a product to cart after emptying cart shows correct delivery fees" do diff --git a/spec/support/spree/init.rb b/spec/support/spree/init.rb index c60c7bc0d4..0007680de7 100644 --- a/spec/support/spree/init.rb +++ b/spec/support/spree/init.rb @@ -8,21 +8,3 @@ ProductDistribution.class_eval do self.enterprise_fee ||= EnterpriseFee.where(enterprise_id: distributor).first || FactoryGirl.create(:enterprise_fee, enterprise_id: distributor) end end - -Spree::Product.class_eval do - before_validation :init_shipping_method - - def init_shipping_method - FactoryGirl.create(:shipping_method) if Spree::ShippingMethod.where("name != 'Delivery'").empty? - end - -end - -# Create a default shipping method, required when creating orders -Spree::Order.class_eval do - before_create :init_shipping_method - - def init_shipping_method - FactoryGirl.create(:itemwise_shipping_method) unless Spree::ShippingMethod.all.any? { |sm| sm.calculator.is_a? OpenFoodWeb::Calculator::Itemwise } - end -end