Adding ze boilerplate

This commit is contained in:
Will Marshall
2014-02-07 13:55:25 +11:00
parent 26e4adf7a6
commit cec0ad8a83
8 changed files with 113 additions and 0 deletions

View File

@@ -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/

View File

@@ -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/

View File

@@ -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

View File

@@ -0,0 +1,2 @@
module Shop::CheckoutHelper
end

View File

View File

@@ -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

View File

@@ -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

View File

@@ -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