From 6ad30d901d0647031897b6b4eee96b985ca3e42f Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 1 May 2014 16:22:11 +1000 Subject: [PATCH] Tidying down shop/checkout test --- app/controllers/application_controller.rb | 2 +- app/controllers/shop/checkout_controller.rb | 7 ------ app/controllers/shop/shop_controller.rb | 9 +------ app/views/shop/shop/_order_cycles.html.haml | 2 +- .../consumer/shopping/checkout_spec.rb | 24 +++++++++---------- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9e4f4d4832..d9cb36a3e9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base private def require_distributor_chosen - unless current_distributor + unless @distributor = current_distributor redirect_to spree.root_path false end diff --git a/app/controllers/shop/checkout_controller.rb b/app/controllers/shop/checkout_controller.rb index 846da4d17d..f2d79e503a 100644 --- a/app/controllers/shop/checkout_controller.rb +++ b/app/controllers/shop/checkout_controller.rb @@ -8,7 +8,6 @@ class Shop::CheckoutController < Spree::CheckoutController include EnterprisesHelper def edit - binding.pry end def update @@ -70,12 +69,6 @@ class Shop::CheckoutController < Spree::CheckoutController def skip_state_validation? true end - - def set_distributor - unless @distributor = current_distributor - redirect_to main_app.root_path - end - end def load_order @order = current_order diff --git a/app/controllers/shop/shop_controller.rb b/app/controllers/shop/shop_controller.rb index 9db927cece..5ee8cdb19f 100644 --- a/app/controllers/shop/shop_controller.rb +++ b/app/controllers/shop/shop_controller.rb @@ -1,7 +1,6 @@ class Shop::ShopController < BaseController layout "darkswarm" - - before_filter :set_distributor + before_filter :require_distributor_chosen before_filter :set_order_cycles def show @@ -32,12 +31,6 @@ class Shop::ShopController < BaseController private - def set_distributor - unless @distributor = current_distributor - redirect_to root_path - end - end - def set_order_cycles @order_cycles = OrderCycle.with_distributor(@distributor).active diff --git a/app/views/shop/shop/_order_cycles.html.haml b/app/views/shop/shop/_order_cycles.html.haml index 7c5ff51df3..1ec978dce2 100644 --- a/app/views/shop/shop/_order_cycles.html.haml +++ b/app/views/shop/shop/_order_cycles.html.haml @@ -2,7 +2,7 @@ :javascript angular.module('Darkswarm').value('orderCycleData', #{render "shop/shop/order_cycle"}) - - if @order_cycles.empty? + - if @order_cycles and @order_cycles.empty? Orders are currently closed for this hub %p Please contact your hub directly to see if they accept late orders, diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 5d473494ae..efc1d1ab5b 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -18,12 +18,13 @@ feature "As a consumer I want to check out my cart", js: true do add_product_to_cart end - it "shows the current distributor" do + it "shows the current distributor oncheckout" do visit shop_checkout_path + current_path.should == shop_checkout_path page.should have_content distributor.name end - pending "with shipping methods" do + describe "with shipping methods" do let(:sm1) { create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow") } let(:sm2) { create(:shipping_method, require_ship_address: false, name: "Donkeys", description: "blue") } before do @@ -33,8 +34,9 @@ feature "As a consumer I want to check out my cart", js: true do context "on the checkout page" do before do - visit "/shop/checkout" + visit shop_checkout_path end + it "shows all shipping methods, but doesn't show ship address when not needed" do toggle_accordion "Shipping" page.should have_content "Frogs" @@ -54,14 +56,12 @@ feature "As a consumer I want to check out my cart", js: true do end describe "with payment methods" do - let(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") } - let(:pm2) { create(:payment_method, distributors: [distributor]) } - let(:pm3) { create(:payment_method, distributors: [distributor], name: "Paypal", type: "Spree::BillingIntegration::PaypalExpress") } + let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") } + let!(:pm2) { create(:payment_method, distributors: [distributor]) } + let!(:pm3) { create(:payment_method, distributors: [distributor], name: "Paypal", type: "Spree::BillingIntegration::PaypalExpress") } before do - pm1 # Lazy evaluation of ze create()s - pm2 - visit "/shop/checkout" + visit shop_checkout_path toggle_accordion "Payment Details" end @@ -92,8 +92,7 @@ feature "As a consumer I want to check out my cart", js: true do fill_in "Postcode", with: "3066" end click_button "Purchase" - sleep 10 - page.should have_content "Your order has been processed successfully" + page.should have_content "Your order has been processed successfully", wait: 10 end it "takes us to the order confirmation page when submitted with 'same as billing address' checked" do @@ -119,8 +118,7 @@ feature "As a consumer I want to check out my cart", js: true do toggle_accordion "Shipping" check "Shipping address same as billing address?" click_button "Purchase" - sleep 10 - page.should have_content "Your order has been processed successfully" + page.should have_content "Your order has been processed successfully", wait: 10 end end end