From c5270d6fa13b6cef045949c350aa6be6157ff181 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 27 Jun 2012 09:06:18 +1000 Subject: [PATCH] Set shipping address from distributor, fix zone init in checkout spec --- app/models/spree/order_decorator.rb | 24 +++++++++++------------- spec/requests/consumer/checkout_spec.rb | 11 +++++++++-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 486af60695..673294f16a 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -17,20 +17,18 @@ Spree::Order.class_eval do - # before_validation :shipping_address_from_distributor + before_validation :shipping_address_from_distributor private - # def shipping_address_from_distributor - # if distributor - # ship_address.firstname = bill_address.firstname - # ship_address.lastname = bill_address.lastname - # ship_address.phone = bill_address.phone + def shipping_address_from_distributor + if distributor + self.ship_address = distributor.pickup_address.clone - # ship_address.address1 = distributor.pickup_address - # ship_address.city = distributor.city - # ship_address.zipcode = distributor.post_code - # ship_address.state = distributor.state - # ship_address.country_id = distributor.country_id - # end - # end + if bill_address + self.ship_address.firstname = bill_address.firstname + self.ship_address.lastname = bill_address.lastname + self.ship_address.phone = bill_address.phone + end + end + end end diff --git a/spec/requests/consumer/checkout_spec.rb b/spec/requests/consumer/checkout_spec.rb index 091dad8118..b4e04f4dee 100644 --- a/spec/requests/consumer/checkout_spec.rb +++ b/spec/requests/consumer/checkout_spec.rb @@ -10,11 +10,18 @@ feature %q{ background do @distributor = create(:distributor, :name => 'Edible garden', - :pickup_address => create(:address, :address1 => '12 Bungee Rd', :city => 'Carion'), - :pickup_times => 'Tuesday, 4 PM') + :pickup_address => create(:address, + :address1 => '12 Bungee Rd', + :city => 'Carion', + :zipcode => 3056, + :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]) @zone = create(:zone) + c = Spree::Country.find_by_name('Australia') + Spree::ZoneMember.create(:zoneable => c, :zone => @zone) create(:shipping_method, zone: @zone) create(:payment_method) end