From 871637c4af9bb082b2578eedf1020fbcccf1fcf2 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Wed, 12 Feb 2014 12:31:37 +1100 Subject: [PATCH] NO CAN HAZ EMPTY CART PAGE --- app/controllers/shop/checkout_controller.rb | 9 +++++++++ .../features/consumer/shopping/checkout_spec.rb | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/controllers/shop/checkout_controller.rb b/app/controllers/shop/checkout_controller.rb index 1281f75b6b..71b30848c2 100644 --- a/app/controllers/shop/checkout_controller.rb +++ b/app/controllers/shop/checkout_controller.rb @@ -3,6 +3,7 @@ class Shop::CheckoutController < BaseController before_filter :set_distributor before_filter :require_order_cycle + before_filter :require_line_items def new @@ -21,4 +22,12 @@ class Shop::CheckoutController < BaseController redirect_to shop_path end end + + # Y U LOOK AT CART? CART IS EMPTY! + # NO CAN HAZ! + def require_line_items + if current_order.line_items.empty? + redirect_to shop_path + end + end end diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index da0df4fb4f..8cf331db8e 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -5,10 +5,14 @@ include WebHelper feature "As a consumer I want to check out my cart", js: true do let(:distributor) { create(:distributor_enterprise) } + let(:supplier) { create(:supplier_enterprise) } let(:order_cycle) { create(:order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) } + let(:product) { create(:simple_product, supplier: supplier) } before do create_enterprise_group_for distributor + exchange = Exchange.find(order_cycle.exchanges.to_enterprises(distributor).outgoing.first.id) + exchange.variants << product.master end describe "Attempting to access checkout without meeting the preconditions" do @@ -23,10 +27,17 @@ feature "As a consumer I want to check out my cart", js: true do current_path.should == shop_path end + it "redirects to the shop page if the current order is empty" do + select_distributor + select_order_cycle + visit "/shop/checkout" + current_path.should == shop_path + end it "renders checkout if we have distributor and order cycle selected" do select_distributor select_order_cycle + add_product_to_cart visit "/shop/checkout" current_path.should == "/shop/checkout" end @@ -37,6 +48,7 @@ feature "As a consumer I want to check out my cart", js: true do before do select_distributor select_order_cycle + add_product_to_cart end it "renders the login form if user is logged out" do @@ -108,3 +120,8 @@ def select_order_cycle visit "/shop" select exchange.pickup_time, from: "order_cycle_id" end + +def add_product_to_cart + fill_in "variants[#{product.master.id}]", with: 5 + first("form.custom > input.button.right").click +end