From cec0ad8a832d39cb839065c629e5496cdc775f3c Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 7 Feb 2014 13:55:25 +1100 Subject: [PATCH] Adding ze boilerplate --- .../javascripts/shop/checkout.js.coffee | 3 ++ app/assets/stylesheets/shop/checkout.css.scss | 3 ++ app/controllers/shop/checkout_controller.rb | 24 ++++++++++ app/helpers/shop/checkout_helper.rb | 2 + app/views/shop/checkout/new.html.haml | 0 .../shop/checkout_controller_spec.rb | 21 +++++++++ .../consumer/shopping/checkout_spec.rb | 45 +++++++++++++++++++ spec/helpers/shop/checkout_helper_spec.rb | 15 +++++++ 8 files changed, 113 insertions(+) create mode 100644 app/assets/javascripts/shop/checkout.js.coffee create mode 100644 app/assets/stylesheets/shop/checkout.css.scss create mode 100644 app/controllers/shop/checkout_controller.rb create mode 100644 app/helpers/shop/checkout_helper.rb create mode 100644 app/views/shop/checkout/new.html.haml create mode 100644 spec/controllers/shop/checkout_controller_spec.rb create mode 100644 spec/features/consumer/shopping/checkout_spec.rb create mode 100644 spec/helpers/shop/checkout_helper_spec.rb diff --git a/app/assets/javascripts/shop/checkout.js.coffee b/app/assets/javascripts/shop/checkout.js.coffee new file mode 100644 index 0000000000..761567942f --- /dev/null +++ b/app/assets/javascripts/shop/checkout.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/shop/checkout.css.scss b/app/assets/stylesheets/shop/checkout.css.scss new file mode 100644 index 0000000000..727d410b19 --- /dev/null +++ b/app/assets/stylesheets/shop/checkout.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Shop::Checkout controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/shop/checkout_controller.rb b/app/controllers/shop/checkout_controller.rb new file mode 100644 index 0000000000..1281f75b6b --- /dev/null +++ b/app/controllers/shop/checkout_controller.rb @@ -0,0 +1,24 @@ +class Shop::CheckoutController < BaseController + layout 'darkswarm' + + before_filter :set_distributor + before_filter :require_order_cycle + + def new + + end + + private + + def set_distributor + unless @distributor = current_distributor + redirect_to root_path + end + end + + def require_order_cycle + unless current_order_cycle + redirect_to shop_path + end + end +end diff --git a/app/helpers/shop/checkout_helper.rb b/app/helpers/shop/checkout_helper.rb new file mode 100644 index 0000000000..263dcc8321 --- /dev/null +++ b/app/helpers/shop/checkout_helper.rb @@ -0,0 +1,2 @@ +module Shop::CheckoutHelper +end diff --git a/app/views/shop/checkout/new.html.haml b/app/views/shop/checkout/new.html.haml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/controllers/shop/checkout_controller_spec.rb b/spec/controllers/shop/checkout_controller_spec.rb new file mode 100644 index 0000000000..20e0b32c5d --- /dev/null +++ b/spec/controllers/shop/checkout_controller_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Shop::CheckoutController do + it "redirects home when no distributor is selected" do + get :new + 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 + 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(:order_cycle).and_return(double(:order_cycle)) + get :new + response.should be_success + end +end diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb new file mode 100644 index 0000000000..3c328ca8b1 --- /dev/null +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +include AuthenticationWorkflow +include WebHelper + +feature "As a consumer I want to check out my cart", js: true do + describe "Attempting to access checkout without meeting the preconditions" do + let(:distributor) { create(:distributor_enterprise) } + let(:order_cycle) { create(:order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) } + + before do + create_enterprise_group_for distributor + end + + it "redirects to the homepage if no distributor is selected" do + visit "/shop/checkout" + current_path.should == root_path + end + + it "redirects to the shop page if we have a distributor but no order cycle selected" do + select_distributor + 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 + visit "/shop/checkout" + current_path.should == "/shop/checkout" + end + end +end + +def select_distributor + visit "/" + click_link distributor.name +end + +def select_order_cycle + exchange = Exchange.find(order_cycle.exchanges.to_enterprises(distributor).outgoing.first.id) + visit "/shop" + select exchange.pickup_time, from: "order_cycle_id" +end diff --git a/spec/helpers/shop/checkout_helper_spec.rb b/spec/helpers/shop/checkout_helper_spec.rb new file mode 100644 index 0000000000..c9500ab0b6 --- /dev/null +++ b/spec/helpers/shop/checkout_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the Shop::CheckoutHelper. For example: +# +# describe Shop::CheckoutHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +describe Shop::CheckoutHelper do + pending "add some examples to (or delete) #{__FILE__}" +end