diff --git a/app/controllers/shop/checkout_controller.rb b/app/controllers/shop/checkout_controller.rb index ab8c9fe9bb..d7b18c9324 100644 --- a/app/controllers/shop/checkout_controller.rb +++ b/app/controllers/shop/checkout_controller.rb @@ -5,9 +5,9 @@ class Shop::CheckoutController < BaseController before_filter :require_order_cycle before_filter :require_line_items - def new + def edit @order = current_order - @order.bill_address = Spree::Address.new + @order.bill_address ||= Spree::Address.new end private diff --git a/app/views/shop/checkout/new.html.haml b/app/views/shop/checkout/edit.html.haml similarity index 99% rename from app/views/shop/checkout/new.html.haml rename to app/views/shop/checkout/edit.html.haml index 97a582309d..4d4d7dddd8 100644 --- a/app/views/shop/checkout/new.html.haml +++ b/app/views/shop/checkout/edit.html.haml @@ -1,4 +1,5 @@ - unless spree_current_user + .row %section#checkout_login .large-4.columns diff --git a/config/routes.rb b/config/routes.rb index 479970737d..adadef7cf0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,9 +8,11 @@ Openfoodnetwork::Application.routes.draw do end namespace :shop do - resource :checkout, controller: :checkout do - get :new - end + #resource :checkout, only: :edit, controller: :checkout do + #get '', to: "" + #end + get '/checkout', :to => 'checkout#edit' , :as => :checkout + post '/checkout', :to => 'checkout#update' , :as => :update_checkout end resources :enterprises do diff --git a/spec/controllers/shop/checkout_controller_spec.rb b/spec/controllers/shop/checkout_controller_spec.rb index 59b58b49b0..89cf8288ec 100644 --- a/spec/controllers/shop/checkout_controller_spec.rb +++ b/spec/controllers/shop/checkout_controller_spec.rb @@ -1,21 +1,36 @@ require 'spec_helper' describe Shop::CheckoutController do + let(:distributor) { double(:distributor) } + let(:order_cycle) { create(:order_cycle) } + let(:order) { create(:order) } it "redirects home when no distributor is selected" do - get :new + get :edit response.should redirect_to root_path end it "redirects to the shop when no order cycle is selected" do - controller.stub(:current_distributor).and_return(double(:distributor)) - get :new + controller.stub(:current_distributor).and_return(distributor) + get :edit + response.should redirect_to shop_path + end + + it "redirects to the shop when no line items are present" do + controller.stub(:current_distributor).and_return(distributor) + controller.stub(:current_order_cycle).and_return(order_cycle) + controller.stub(:current_order).and_return(order) + order.stub_chain(:line_items, :empty?).and_return true + get :edit response.should redirect_to shop_path end it "renders when both distributor and order cycle is selected" do - controller.stub(:current_distributor).and_return(double(:distributor)) - controller.stub(:current_order_cycle).and_return(create(:order_cycle)) - get :new + controller.stub(:current_distributor).and_return(distributor) + controller.stub(:current_order_cycle).and_return(order_cycle) + controller.stub(:current_order).and_return(order) + order.stub_chain(:line_items, :empty?).and_return false + + get :edit response.should be_success end end