Permalink
Browse files

Merge branch 'cleanup_task_computed_bucket' of github.com:jamescook/f…

…at_free_crm into jamescook-cleanup_task_computed_bucket
  • Loading branch information...
2 parents 934e7db + 890e381 commit 9d9aeb81bceb43358c67f6538c569c5b678a5d86 @steveyken steveyken committed Feb 8, 2014
Showing with 80 additions and 6 deletions.
  1. +30 −6 app/models/polymorphic/task.rb
  2. +50 −0 spec/models/polymorphic/task_spec.rb
@@ -152,21 +152,20 @@ def at_specific_time?
def computed_bucket
return self.bucket if self.bucket != "specific_time"
case
- when self.due_at < Time.zone.now.midnight
+ when overdue?
"overdue"
- when self.due_at >= Time.zone.now.midnight && self.due_at < Time.zone.now.midnight.tomorrow
+ when due_today?
"due_today"
- when self.due_at >= Time.zone.now.midnight.tomorrow && self.due_at < Time.zone.now.midnight.tomorrow + 1.day
+ when due_tomorrow?
"due_tomorrow"
- when self.due_at >= (Time.zone.now.midnight.tomorrow + 1.day) && self.due_at < Time.zone.now.next_week
+ when due_this_week? && !due_today? && !due_tomorrow?
"due_this_week"
- when self.due_at >= Time.zone.now.next_week && self.due_at < (Time.zone.now.next_week.end_of_week + 1.day)
+ when due_next_week?
"due_next_week"
else
"due_later"
end
end
-
# Returns list of tasks grouping them by due date as required by tasks/index.
#----------------------------------------------------------------------------
def self.find_all_grouped(user, view)
@@ -235,6 +234,31 @@ def due_beginning_of_day?
self.due_at.present? && (self.due_at == self.due_at.beginning_of_day)
end
+ #----------------------------------------------------------------------------
+ def overdue?
+ self.due_at < Time.zone.now.midnight
+ end
+
+ #----------------------------------------------------------------------------
+ def due_today?
+ self.due_at.between?(Time.zone.now.midnight, Time.zone.now.end_of_day)
+ end
+
+ #----------------------------------------------------------------------------
+ def due_tomorrow?
+ self.due_at.between?(Time.zone.now.midnight.tomorrow, Time.zone.now.tomorrow.end_of_day)
+ end
+
+ #----------------------------------------------------------------------------
+ def due_this_week?
+ self.due_at.between?(Time.zone.now.beginning_of_week, Time.zone.now.end_of_week)
+ end
+
+ #----------------------------------------------------------------------------
+ def due_next_week?
+ self.due_at.between?(Time.zone.now.next_week, Time.zone.now.next_week.end_of_week)
+ end
+
#----------------------------------------------------------------------------
def notify_assignee
if self.assigned_to
@@ -227,6 +227,56 @@
end
end
+ describe "task.computed_bucket" do
+ context "when overdue" do
+ subject { described_class.new(:due_at => 1.days.ago, :bucket => "specific_time") }
+
+ it "returns a sensible value" do
+ subject.computed_bucket.should == "overdue"
+ end
+ end
+
+ context "when due today" do
+ subject { described_class.new(:due_at => Time.now, :bucket => "specific_time") }
+
+ it "returns a sensible value" do
+ subject.computed_bucket.should == "due_today"
+ end
+ end
+
+ context "when due tomorrow" do
+ subject { described_class.new(:due_at => 1.days.from_now.end_of_day, :bucket => "specific_time") }
+
+ it "returns a sensible value" do
+ subject.computed_bucket.should == "due_tomorrow"
+ end
+ end
+
+ context "when due this week" do
+ subject { described_class.new(:due_at => Time.zone.now.end_of_week, :bucket => "specific_time") }
+
+ it "returns a sensible value" do
+ subject.computed_bucket.should == "due_this_week"
+ end
+ end
+
+ context "when due next week" do
+ subject { described_class.new(:due_at => Time.zone.now.next_week, :bucket => "specific_time") }
+
+ it "returns a sensible value" do
+ subject.computed_bucket.should == "due_next_week"
+ end
+ end
+
+ context "when due later" do
+ subject { described_class.new(:due_at => 1.month.from_now, :bucket => "specific_time") }
+
+ it "returns a sensible value" do
+ subject.computed_bucket.should == "due_later"
+ end
+ end
+ end
+
describe "task.at_specific_time?" do
context "when the due date is at the beginning of the day" do
subject { described_class.new(due_at: Time.zone.now.beginning_of_day) }

0 comments on commit 9d9aeb8

Please sign in to comment.