Do not load Order Cycles that closed more than a month a go

This commit is contained in:
Victor Nava
2015-03-05 16:03:48 +11:00
parent 4e1eb33ff5
commit 1b709a3e03
5 changed files with 16 additions and 4 deletions

View File

@@ -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

View File

@@ -79,7 +79,7 @@ module Admin
ocs.undated +
ocs.soonest_closing +
ocs.soonest_opening +
ocs.most_recently_closed
ocs.recently_closed
end
private

View File

@@ -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|

View File

@@ -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

View File

@@ -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)