mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
We can now hit the index page
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
class ShopController < BaseController
|
||||
layout "darkswarm"
|
||||
|
||||
before_filter :set_distributor
|
||||
before_filter :set_order_cycles
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_distributor
|
||||
@distributor = current_distributor
|
||||
end
|
||||
|
||||
|
||||
def set_order_cycles
|
||||
@order_cycles = OrderCycle.with_distributor(@distributor).active
|
||||
|
||||
# And default to the only order cycle if there's only the one
|
||||
if @order_cycles.count == 1
|
||||
current_order(true).set_order_cycle! @order_cycles.first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,8 +52,8 @@ module OrderCyclesHelper
|
||||
OpenFoodNetwork::FeatureToggle.enabled? :order_cycles
|
||||
end
|
||||
|
||||
def pickup_time
|
||||
current_order_cycle.exchanges.to_enterprises(current_distributor).outgoing.first.pickup_time
|
||||
def pickup_time(order_cycle = current_order_cycle)
|
||||
order_cycle.exchanges.to_enterprises(current_distributor).outgoing.first.pickup_time
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
module ShopHelper
|
||||
|
||||
def order_cycles_name_and_pickup_times(order_cycles)
|
||||
order_cycles.map do |oc|
|
||||
[
|
||||
pickup_time(oc),
|
||||
oc.id
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
= @distributor.name
|
||||
|
||||
Ready for:
|
||||
= select_tag :order_cycle_id, options_for_select(order_cycles_name_and_pickup_times(@order_cycles), current_order_cycle.id)
|
||||
|
||||
%description
|
||||
= @distributor.long_description.andand.html_safe
|
||||
|
||||
|
||||
|
||||
= render partial: "enterprises/contact_us"
|
||||
= render partial: "enterprises/about_us"
|
||||
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe DistributorsController do
|
||||
it "should set the distributor when loading show"
|
||||
describe ShopController do
|
||||
it "should select an order cycle when only one order cycle is open" do
|
||||
d = create(:distributor_enterprise)
|
||||
oc1 = create(:order_cycle, distributors: [d])
|
||||
controller.stub(:current_distributor).and_return d
|
||||
spree_get :index
|
||||
controller.current_order_cycle.should == oc1
|
||||
end
|
||||
|
||||
it "should not set an order cycle when multiple order cycles are open" do
|
||||
d = create(:distributor_enterprise)
|
||||
oc1 = create(:order_cycle, distributors: [d])
|
||||
oc2 = create(:order_cycle, distributors: [d])
|
||||
controller.stub(:current_distributor).and_return d
|
||||
spree_get :index
|
||||
controller.current_order_cycle.should == nil
|
||||
end
|
||||
|
||||
it "should create/load an order when loading show"
|
||||
end
|
||||
|
||||
@@ -21,11 +21,11 @@ feature "As a consumer I want to shop with a distributor" do
|
||||
it "selects an order cycle if only one is open" do
|
||||
# create order cycle
|
||||
oc1 = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor])
|
||||
exchange = Exchange.find(oc1.exchanges.to_enterprises(d).outgoing.first.id)
|
||||
exchange = Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id)
|
||||
exchange.update_attribute :pickup_time, "turtles"
|
||||
|
||||
visit shop_index_path
|
||||
page.should have_selector "option[selected]", text: 'Packing'
|
||||
page.should have_selector "option[selected]", text: 'turtles'
|
||||
|
||||
# Should see order cycle selected in dropdown
|
||||
# (Should also render products)
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the DistributorsHelper. For example:
|
||||
#
|
||||
# describe DistributorsHelper 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 DistributorsHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -32,4 +32,17 @@ describe OrderCyclesHelper do
|
||||
helper.stub!(:current_distributor).and_return d
|
||||
helper.pickup_time.should == "turtles"
|
||||
end
|
||||
|
||||
it "should give me the pickup time for any order cycle" do
|
||||
d = create(:distributor_enterprise, name: 'Green Grass')
|
||||
oc1 = create(:simple_order_cycle, name: 'oc 1', distributors: [d])
|
||||
oc2= create(:simple_order_cycle, name: 'oc 1', distributors: [d])
|
||||
|
||||
exchange = Exchange.find(oc2.exchanges.to_enterprises(d).outgoing.first.id)
|
||||
exchange.update_attribute :pickup_time, "turtles"
|
||||
|
||||
helper.stub!(:current_order_cycle).and_return oc1
|
||||
helper.stub!(:current_distributor).and_return d
|
||||
helper.pickup_time(oc2).should == "turtles"
|
||||
end
|
||||
end
|
||||
|
||||
11
spec/helpers/shop_helper_spec.rb
Normal file
11
spec/helpers/shop_helper_spec.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require 'spec_helper'
|
||||
describe ShopHelper do
|
||||
|
||||
it "should build order cycle select options" do
|
||||
d = create(:distributor_enterprise)
|
||||
o1 = create(:simple_order_cycle, distributors: [d])
|
||||
helper.stub(:current_distributor).and_return d
|
||||
|
||||
helper.order_cycles_name_and_pickup_times([o1]).should == [[helper.pickup_time(o1), o1.id]]
|
||||
end
|
||||
end
|
||||
@@ -30,6 +30,13 @@ describe OrderCycle do
|
||||
oc.exchanges.count.should == 3
|
||||
end
|
||||
|
||||
it "gives me the outgoing exchange" do
|
||||
d = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle), distributors: [d])
|
||||
|
||||
oc.sender.should == d
|
||||
end
|
||||
|
||||
it "finds order cycles in various stages of their lifecycle" do
|
||||
oc_active = create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: 1.week.from_now)
|
||||
oc_not_yet_open = create(:simple_order_cycle, orders_open_at: 1.week.from_now, orders_close_at: 2.weeks.from_now)
|
||||
|
||||
Reference in New Issue
Block a user