From 73e601315bee7927c46c45cce86d182c74fe4bee Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 29 Jun 2012 11:50:43 +1000 Subject: [PATCH] Add acceptance spec for itemwise shipping fees --- spec/factories.rb | 8 ++++++++ spec/requests/consumer/checkout_spec.rb | 27 ++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index 804c5d5678..a97e6cf445 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -25,6 +25,14 @@ FactoryGirl.define do distributor { |pd| Spree::Distributor.first || FactoryGirl.create(:distributor) } shipping_method { |pd| Spree::ShippingMethod.first || FactoryGirl.create(:shipping_method) } end + + factory :itemwise_shipping_method, :parent => :shipping_method do + name 'Delivery' + calculator { FactoryGirl.build(:itemwise_calculator) } + end + + factory :itemwise_calculator, :class => OpenFoodWeb::Calculator::Itemwise do + end end diff --git a/spec/requests/consumer/checkout_spec.rb b/spec/requests/consumer/checkout_spec.rb index 7040119afe..6c33d4c78b 100644 --- a/spec/requests/consumer/checkout_spec.rb +++ b/spec/requests/consumer/checkout_spec.rb @@ -17,12 +17,25 @@ feature %q{ :state => Spree::State.find_by_name('Victoria'), :country => Spree::Country.find_by_name('Australia')), :pickup_times => 'Tuesday, 4 PM') - @product = create(:product, :name => 'Fuji apples', :distributors => [@distributor]) + + @shipping_method_1 = create(:shipping_method) + @shipping_method_1.calculator.set_preference :amount, 1 + @shipping_method_1.calculator.save! + + @shipping_method_2 = create(:shipping_method) + @shipping_method_2.calculator.set_preference :amount, 2 + @shipping_method_2.calculator.save! + + @product_1 = create(:product, :name => 'Fuji apples') + @product_1.product_distributions.create(:distributor => @distributor, :shipping_method => @shipping_method_1) + + @product_2 = create(:product, :name => 'Garlic') + @product_2.product_distributions.create(:distributor => @distributor, :shipping_method => @shipping_method_2) @zone = create(:zone) c = Spree::Country.find_by_name('Australia') Spree::ZoneMember.create(:zoneable => c, :zone => @zone) - create(:shipping_method, zone: @zone) + create(:itemwise_shipping_method, zone: @zone) create(:payment_method) end @@ -32,8 +45,13 @@ feature %q{ click_link 'Fuji apples' click_button 'Add To Cart' + click_link 'Continue shopping' + + click_link 'Garlic' + click_button 'Add To Cart' click_link 'Checkout' + # -- Checkout: Address fill_in_fields('order_bill_address_attributes_firstname' => 'Joe', 'order_bill_address_attributes_lastname' => 'Luck', 'order_bill_address_attributes_address1' => '19 Sycamore Lane', @@ -44,6 +62,7 @@ feature %q{ select('Australia', :from => 'order_bill_address_attributes_country_id') select('Victoria', :from => 'order_bill_address_attributes_state_id') + # Distributor details should be displayed within('fieldset#shipping') do [@distributor.name, @distributor.pickup_address.address1, @@ -63,10 +82,12 @@ feature %q{ end click_button 'Save and Continue' - #display delivery details? + # -- Checkout: Delivery + page.should have_selector 'label', :text => "Delivery $3.00" click_button 'Save and Continue' + # -- Checkout: Payment click_button 'Save and Continue' page.should have_content('Your order has been processed successfully')