Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uk/hub closed new #1522

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/controllers/base_controller.rb
Original file line number Diff line number Diff line change
@@ -23,6 +23,11 @@ class BaseController < ApplicationController
private

def set_order_cycles
unless @distributor.ready_for_checkout?
@order_cycles = OrderCycle.where('false')
return
end

@order_cycles = OrderCycle.with_distributor(@distributor).active
.order(@distributor.preferred_shopfront_order_cycle_order)

2 changes: 1 addition & 1 deletion lib/open_food_network/enterprise_injection_data.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module OpenFoodNetwork
class EnterpriseInjectionData
def active_distributors
@active_distributors ||= Enterprise.distributors_with_active_order_cycles
@active_distributors ||= Enterprise.distributors_with_active_order_cycles.ready_for_checkout
end

def earliest_closing_times
4 changes: 3 additions & 1 deletion spec/controllers/shop_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'

describe ShopController do
let(:distributor) { create(:distributor_enterprise) }
let!(:pm) { create(:payment_method) }
let!(:sm) { create(:shipping_method) }
let(:distributor) { create(:distributor_enterprise, payment_methods: [pm], shipping_methods: [sm]) }

it "redirects to the home page if no distributor is selected" do
spree_get :show
2 changes: 1 addition & 1 deletion spec/controllers/shops_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) }

before do
Enterprise.stub(:distributors_with_active_order_cycles) { [distributor] }
Enterprise.stub_chain("distributors_with_active_order_cycles.ready_for_checkout") { [distributor] }
end

# Exclusion from actual rendered view handled in features/consumer/home
20 changes: 17 additions & 3 deletions spec/features/consumer/shops_spec.rb
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@

let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) }
let(:d1) { create(:distributor_enterprise) }
let(:d2) { create(:distributor_enterprise) }
let!(:d1) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let!(:d2) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) }
let!(:producer) { create(:supplier_enterprise) }
let!(:er) { create(:enterprise_relationship, parent: distributor, child: producer) }
@@ -57,6 +57,20 @@
end
end

describe "showing available hubs" do
let!(:hub) { create(:distributor_enterprise, with_payment_and_shipping: false) }
let!(:order_cycle) { create(:simple_order_cycle, distributors: [hub], coordinator: hub) }
let!(:producer) { create(:supplier_enterprise) }
let!(:er) { create(:enterprise_relationship, parent: hub, child: producer) }

it "does not show hubs that are not ready for checkout" do
visit shops_path

Enterprise.ready_for_checkout.should_not include hub
page.should_not have_content hub.name
end
end

describe "filtering by product property" do
let!(:order_cycle) { create(:simple_order_cycle, distributors: [d1, d2], coordinator: create(:distributor_enterprise)) }
let!(:p1) { create(:simple_product, supplier: producer) }
@@ -92,7 +106,7 @@
describe "taxon badges" do
let!(:closed_oc) { create(:closed_order_cycle, distributors: [shop], variants: [p_closed.variants.first]) }
let!(:p_closed) { create(:simple_product, taxons: [taxon_closed]) }
let(:shop) { create(:distributor_enterprise) }
let(:shop) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:taxon_closed) { create(:taxon, name: 'Closed') }

describe "open shops" do