mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add order cycle active and inactive scopes
This commit is contained in:
@@ -9,6 +9,9 @@ class OrderCycle < ActiveRecord::Base
|
||||
|
||||
validates_presence_of :name, :coordinator_id
|
||||
|
||||
scope :active, lambda { where('orders_open_at <= ? AND orders_close_at >= ?', Time.now, Time.now) }
|
||||
scope :inactive, lambda { where('orders_open_at > ? OR orders_close_at < ?', Time.now, Time.now) }
|
||||
|
||||
|
||||
def suppliers
|
||||
self.exchanges.where(:receiver_id => self.coordinator).map(&:sender).uniq
|
||||
|
||||
@@ -31,6 +31,15 @@ describe OrderCycle do
|
||||
oc.exchanges.count.should == 3
|
||||
end
|
||||
|
||||
it "finds active and inactive order cycles" 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)
|
||||
|
||||
OrderCycle.active.should == [oc_active]
|
||||
OrderCycle.inactive.sort.should == [oc_not_yet_open, oc_already_closed].sort
|
||||
end
|
||||
|
||||
it "reports its suppliers" do
|
||||
oc = create(:simple_order_cycle)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user