Show undated order cycles on index page

This commit is contained in:
Rohan Mitchell
2013-12-13 14:51:43 +11:00
parent 6e36142809
commit 124b6df75d
5 changed files with 34 additions and 7 deletions

View File

@@ -72,7 +72,8 @@ module Admin
def collection
ocs = OrderCycle.managed_by(spree_current_user)
ocs.soonest_closing +
ocs.undated +
ocs.soonest_closing +
ocs.soonest_opening +
ocs.most_recently_closed
end

View File

@@ -18,7 +18,9 @@ module OrderCyclesHelper
end
def order_cycle_status_class(order_cycle)
if order_cycle.upcoming?
if order_cycle.undated?
'undated'
elsif order_cycle.upcoming?
'upcoming'
elsif order_cycle.open?
'open'

View File

@@ -16,6 +16,7 @@ class OrderCycle < ActiveRecord::Base
scope :inactive, lambda { where('order_cycles.orders_open_at > ? OR order_cycles.orders_close_at < ?', Time.now, Time.now) }
scope :upcoming, lambda { where('order_cycles.orders_open_at > ?', Time.now) }
scope :closed, lambda { where('order_cycles.orders_close_at < ?', Time.now) }
scope :undated, where(orders_open_at: nil, orders_close_at: nil)
scope :distributing_product, lambda { |product|
joins(:exchanges => :variants).
@@ -111,16 +112,21 @@ class OrderCycle < ActiveRecord::Base
self.variants.include? variant
end
def undated?
self.orders_open_at.nil? && self.orders_close_at.nil?
end
def upcoming?
Time.now < self.orders_open_at
self.orders_open_at && Time.now < self.orders_open_at
end
def open?
Time.now > self.orders_open_at && Time.now < self.orders_close_at
self.orders_open_at && self.orders_close_at &&
Time.now > self.orders_open_at && Time.now < self.orders_close_at
end
def closed?
Time.now > self.orders_close_at
self.orders_close_at && Time.now > self.orders_close_at
end
def exchange_for_distributor(distributor)

View File

@@ -29,6 +29,8 @@ feature %q{
oc5 = create(:simple_order_cycle, name: '5',
orders_open_at: 1.month.ago, orders_close_at: 2.weeks.ago)
oc1 = create(:order_cycle, name: '1')
oc0 = create(:simple_order_cycle, name: '0',
orders_open_at: nil, orders_close_at: nil)
# When I go to the admin order cycles page
login_to_admin_section
@@ -36,9 +38,10 @@ feature %q{
# Then the order cycles should be ordered correctly
page.all('#listing_order_cycles tr td:first-child').map(&:text).should ==
['1', '2', '3', '4', '5', '6']
['0', '1', '2', '3', '4', '5', '6']
# And the rows should have the correct classes
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc0.id}.undated"
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc1.id}.open"
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc2.id}.open"
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc3.id}.upcoming"
@@ -47,7 +50,8 @@ feature %q{
page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc6.id}.closed"
# And I should see all the details for an order cycle
within('table#listing_order_cycles tbody tr:first-child') do
# (the table includes a hidden field between each row, making this nth-child(3) instead of 2)
within('table#listing_order_cycles tbody tr:nth-child(3)') do
# Then I should see the basic fields
page.should have_selector 'a', text: oc1.name

View File

@@ -34,11 +34,13 @@ describe OrderCycle 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)
oc_already_closed = create(:simple_order_cycle, orders_open_at: 2.weeks.ago, orders_close_at: 1.week.ago)
oc_undated = create(:simple_order_cycle, orders_open_at: nil, orders_close_at: nil)
OrderCycle.active.should == [oc_active]
OrderCycle.inactive.sort.should == [oc_not_yet_open, oc_already_closed].sort
OrderCycle.upcoming.should == [oc_not_yet_open]
OrderCycle.closed.should == [oc_already_closed]
OrderCycle.undated.should == [oc_undated]
end
it "finds order cycles accessible by a user" do
@@ -248,6 +250,7 @@ describe OrderCycle do
it "reports status when an order cycle is upcoming" do
Timecop.freeze(oc.orders_open_at - 1.second) do
oc.should_not be_undated
oc.should be_upcoming
oc.should_not be_open
oc.should_not be_closed
@@ -255,6 +258,7 @@ describe OrderCycle do
end
it "reports status when an order cycle is open" do
oc.should_not be_undated
oc.should_not be_upcoming
oc.should be_open
oc.should_not be_closed
@@ -262,11 +266,21 @@ describe OrderCycle do
it "reports status when an order cycle has closed" do
Timecop.freeze(oc.orders_close_at + 1.second) do
oc.should_not be_undated
oc.should_not be_upcoming
oc.should_not be_open
oc.should be_closed
end
end
it "reports status when an order cycle is undated" do
oc.update_attributes!(orders_open_at: nil, orders_close_at: nil)
oc.should be_undated
oc.should_not be_upcoming
oc.should_not be_open
oc.should_not be_closed
end
end
it "clones itself" do