mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Do not load Order Cycles that closed more than a month a go
This commit is contained in:
@@ -325,7 +325,7 @@ GEM
|
||||
mail (2.5.4)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
method_source (0.8.1)
|
||||
method_source (0.8.2)
|
||||
mime-types (1.25.1)
|
||||
mini_portile (0.6.2)
|
||||
momentjs-rails (2.5.1)
|
||||
@@ -509,7 +509,7 @@ GEM
|
||||
xml-simple (1.1.4)
|
||||
xpath (2.0.0)
|
||||
nokogiri (~> 1.3)
|
||||
zeus (0.13.3)
|
||||
zeus (0.15.4)
|
||||
method_source (>= 0.6.7)
|
||||
|
||||
PLATFORMS
|
||||
|
||||
@@ -79,7 +79,7 @@ module Admin
|
||||
ocs.undated +
|
||||
ocs.soonest_closing +
|
||||
ocs.soonest_opening +
|
||||
ocs.most_recently_closed
|
||||
ocs.recently_closed
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -19,7 +19,9 @@ class OrderCycle < ActiveRecord::Base
|
||||
scope :undated, where(orders_open_at: nil, orders_close_at: nil)
|
||||
|
||||
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.
|
||||
scope :most_recently_closed, lambda { closed.order('order_cycles.orders_close_at DESC') }
|
||||
scope :recently_closed, lambda { where("order_cycles.orders_close_at >= ?", 31.days.ago).order("order_cycles.orders_close_at DESC") }
|
||||
scope :soonest_opening, lambda { upcoming.order('order_cycles.orders_open_at ASC') }
|
||||
|
||||
scope :distributing_product, lambda { |product|
|
||||
|
||||
@@ -585,9 +585,9 @@ ActiveRecord::Schema.define(:version => 20150220035501) do
|
||||
t.string "email"
|
||||
t.text "special_instructions"
|
||||
t.integer "distributor_id"
|
||||
t.integer "order_cycle_id"
|
||||
t.string "currency"
|
||||
t.string "last_ip_address"
|
||||
t.integer "order_cycle_id"
|
||||
t.integer "cart_id"
|
||||
end
|
||||
|
||||
|
||||
@@ -90,6 +90,16 @@ describe OrderCycle do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#recently_closed" do
|
||||
it "finds the orders closed in the last 30 days sorted in descending order" do
|
||||
oc1 = create(:simple_order_cycle, orders_close_at: 1.day.ago)
|
||||
oc2 = create(:simple_order_cycle, orders_close_at: 30.days.ago)
|
||||
create(:simple_order_cycle, orders_close_at: 31.days.ago)
|
||||
|
||||
OrderCycle.recently_closed.should == [oc1 , oc2]
|
||||
end
|
||||
end
|
||||
|
||||
it "finds the most recently closed order cycles" do
|
||||
oc1 = create(:simple_order_cycle, orders_close_at: 2.hours.ago)
|
||||
oc2 = create(:simple_order_cycle, orders_close_at: 1.hour.ago)
|
||||
|
||||
Reference in New Issue
Block a user