From 0e8443e118d788fdb8919f9e9fee38ecfda113c3 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 10 Sep 2013 11:28:49 +1000 Subject: [PATCH] Rename 'Change Pick-up Date' to 'Change Collection Date'. Fix this to clear the cart. Do not clear distributor when setting Order.order_cycle to nil. --- .../spree/orders_controller_decorator.rb | 5 ++-- app/models/spree/order_decorator.rb | 2 +- app/views/order_cycles/_selection.html.haml | 4 +-- spec/features/consumer/order_cycles_spec.rb | 27 +++++++++++++++++++ spec/models/order_spec.rb | 4 +++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 5e20d3d7d1..c1b18678c0 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -64,10 +64,9 @@ Spree::OrdersController.class_eval do def clear @order = current_order(true) - current_distributor = @order.distributor - @order.order_cycle = nil + @order.empty! @order.set_order_cycle! nil - redirect_to main_app.shop_enterprise_path(current_distributor.id) + redirect_to main_app.enterprise_path(@order.distributor.id) end private diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 8c265a4606..d994584049 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -51,7 +51,7 @@ Spree::Order.class_eval do def set_order_cycle!(order_cycle) self.order_cycle = order_cycle - self.distributor = nil unless self.order_cycle.andand.has_distributor? distributor + self.distributor = nil unless order_cycle.nil? || order_cycle.has_distributor?(distributor) save! end diff --git a/app/views/order_cycles/_selection.html.haml b/app/views/order_cycles/_selection.html.haml index df056b6e42..73f351ded1 100644 --- a/app/views/order_cycles/_selection.html.haml +++ b/app/views/order_cycles/_selection.html.haml @@ -4,9 +4,9 @@ .columns.six %h1= "Your order will be ready on #{current_order_cycle.exchanges.to_enterprises(current_distributor).outgoing.first.pickup_time}" %i - = link_to 'Change Pick-up Date', spree.clear_orders_path, :id => 'reset_order_cycle' + = link_to 'Change Collection Date', spree.clear_orders_path, :id => 'reset_order_cycle' (This will reset your cart) - %p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore + %p.hide Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore .columns.five .row %strong ORDERS CLOSE diff --git a/spec/features/consumer/order_cycles_spec.rb b/spec/features/consumer/order_cycles_spec.rb index 539c5a75a6..d353e9394b 100644 --- a/spec/features/consumer/order_cycles_spec.rb +++ b/spec/features/consumer/order_cycles_spec.rb @@ -31,6 +31,33 @@ feature %q{ end end + + scenario "changing order cycle", js: true do + s = create(:supplier_enterprise) + d = create(:distributor_enterprise, name: 'Green Grass') + p = create(:simple_product, supplier: s) + oc = create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master]) + + visit spree.root_path + click_link d.name + select_by_value oc.id, from: 'order_order_cycle_id' + + click_link p.name + click_button 'Add To Cart' + + click_link 'Continue shopping' + click_link 'Change Collection Date' + + # Then we should be back at the landing page with a reset cart + page.should have_content 'Green Grass' + page.should have_content 'When do you want your order?' + cart = Spree::Order.last + cart.distributor.should == d + cart.order_cycle.should be_nil + cart.line_items.should be_empty + end + + scenario "viewing order cycle and distributor choices", :future => true do # When I go to the product listing page visit spree.products_path diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 12b4747034..1c285ec45a 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -171,10 +171,14 @@ describe Spree::Order do it "clears the order cycle when setting to nil" do oc = create(:simple_order_cycle) + d = create(:distributor_enterprise) subject.set_order_cycle! oc + subject.distributor = d + subject.set_order_cycle! nil subject.order_cycle.should be_nil + subject.distributor.should == d end end