Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 9d9aeb81bceb43358c67f6538c569c5b678a5d86 2 parents 934e7db + 890e381
@steveyken steveyken authored
View
36 app/models/polymorphic/task.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)
@@ -236,6 +235,31 @@ def due_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
# Notify assignee.
View
50 spec/models/polymorphic/task_spec.rb
@@ -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) }
Please sign in to comment.
Something went wrong with that request. Please try again.