Merge remote-tracking branch 'origin/master' into groups

This commit is contained in:
Maikel Linke
2016-02-05 11:05:40 +11:00
2 changed files with 23 additions and 3 deletions

View File

@@ -16,7 +16,7 @@ class OrderCycle < ActiveRecord::Base
scope :inactive, lambda { where('order_cycles.orders_open_at > ? OR order_cycles.orders_close_at < ?', Time.zone.now, Time.zone.now) }
scope :upcoming, lambda { where('order_cycles.orders_open_at > ?', Time.zone.now) }
scope :closed, lambda { where('order_cycles.orders_close_at < ?', Time.zone.now).order("order_cycles.orders_close_at DESC") }
scope :undated, where(orders_open_at: nil, orders_close_at: nil)
scope :undated, where('order_cycles.orders_open_at IS NULL OR orders_close_at IS NULL')
scope :soonest_closing, lambda { active.order('order_cycles.orders_close_at ASC') }
# TODO This method returns all the closed orders. So maybe we can replace it with :recently_closed.
@@ -182,7 +182,7 @@ class OrderCycle < ActiveRecord::Base
end
def undated?
self.orders_open_at.nil? && self.orders_close_at.nil?
self.orders_open_at.nil? || self.orders_close_at.nil?
end
def upcoming?

View File

@@ -35,12 +35,14 @@ describe OrderCycle do
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)
oc_undated_open = create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: nil)
oc_undated_close = create(:simple_order_cycle, orders_open_at: nil, orders_close_at: 1.week.from_now)
OrderCycle.active.should == [oc_active]
OrderCycle.inactive.should match_array [oc_not_yet_open, oc_already_closed]
OrderCycle.upcoming.should == [oc_not_yet_open]
OrderCycle.closed.should == [oc_already_closed]
OrderCycle.undated.should == [oc_undated]
OrderCycle.undated.should == [oc_undated, oc_undated_open, oc_undated_close]
end
it "finds order cycles accessible by a user" do
@@ -356,6 +358,24 @@ describe OrderCycle do
oc.should_not be_open
oc.should_not be_closed
end
it "reports status when an order cycle is partially dated - opening time only" do
oc.update_attributes!(orders_close_at: nil)
oc.should be_undated
oc.should_not be_upcoming
oc.should_not be_open
oc.should_not be_closed
end
it "reports status when an order cycle is partially dated - closing time only" do
oc.update_attributes!(orders_open_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