When there are no order cycles open, display an 'orders closed' message

This commit is contained in:
Rohan Mitchell
2013-10-24 10:32:30 +11:00
parent e3307623dd
commit fb22b5e2b7
5 changed files with 43 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
class BaseController < ApplicationController
include Spree::Core::ControllerHelpers
include Spree::Core::ControllerHelpers::RespondWith
include OrderCyclesHelper
helper 'spree/base'

View File

@@ -25,6 +25,9 @@ class OrderCycle < ActiveRecord::Base
joins(:exchanges).merge(Exchange.outgoing).where('exchanges.receiver_id = ?', distributor)
}
scope :most_recently_closed, lambda {
where('orders_close_at < ?', Time.now).order('orders_close_at DESC')
}
scope :managed_by, lambda { |user|
if user.has_spree_role?('admin')

View File

@@ -13,6 +13,21 @@
.countdown-panel
%h1= distance_of_time_in_words_to_now(current_order_cycle.orders_close_at)
- elsif order_cycle_options.empty?
.columns.two= image_tag 'pickup.png'
.columns.nine
%h2 Orders are currently closed for this hub
%p
- if OrderCycle.most_recently_closed.present?
The last cycle closed
= distance_of_time_in_words_to_now OrderCycle.most_recently_closed.first.orders_close_at
ago.
Please contact your hub directly to see if they accept late orders, or wait until the next cycle opens.
%p
= "Email: #{current_distributor.email}" if current_distributor.email
%br/
= "Phone: #{current_distributor.phone}" if current_distributor.phone
- else
.columns.two= image_tag 'pickup.png'

View File

@@ -45,6 +45,22 @@ feature %q{
page.should have_content 'Your order will be ready on'
end
scenario "when there are no available order cycles" do
Timecop.freeze do
d = create(:distributor_enterprise, name: 'Green Grass')
oc1 = create(:simple_order_cycle, name: 'oc 1', distributors: [d], orders_close_at: 5.minutes.ago)
visit spree.root_path
click_link d.name
page.should have_content "Orders are currently closed for this hub"
page.should have_content "The last cycle closed 5 minutes ago."
page.should have_content "Please contact your hub directly to see if they accept late orders, or wait until the next cycle opens."
page.should have_content d.email
page.should have_content d.phone
end
end
scenario "changing order cycle", js: true do
s = create(:supplier_enterprise)

View File

@@ -81,6 +81,14 @@ describe OrderCycle do
end
end
it "finds the most recently closed order cycles" do
oc1 = create(:order_cycle, orders_close_at: 2.hours.ago)
oc2 = create(:order_cycle, orders_close_at: 1.hour.ago)
oc3 = create(:order_cycle, orders_close_at: 1.hour.from_now)
OrderCycle.most_recently_closed.should == [oc2, oc1]
end
describe "finding order cycles with a particular distributor" do
let(:c) { create(:supplier_enterprise) }
let(:d) { create(:distributor_enterprise) }