added #is_today and #tasks_today
This commit is contained in:
parent
130eebb081
commit
0d4d1e14f7
@ -77,6 +77,15 @@ module WorkingClass
|
||||
alias :is_tomorrow? :is_tomorrow
|
||||
alias :tomorrow? :is_tomorrow
|
||||
|
||||
# Returns true if the Task is due today.
|
||||
# A finished task or a Task without a date is never today.
|
||||
#
|
||||
# @return [Boolean] true if the task is due today
|
||||
def is_today
|
||||
!@is_finished and @date == Date.today
|
||||
end
|
||||
|
||||
alias :is_today? :is_today
|
||||
alias :today? :is_today
|
||||
end
|
||||
end
|
||||
|
@ -29,6 +29,14 @@ module WorkingClass
|
||||
@tasks.select { |task| task.is_upcoming }
|
||||
end
|
||||
|
||||
# Returns all the tasks that are due today
|
||||
#
|
||||
# @return [Array<WorkingClass::Task>] an Array with the tasks due today
|
||||
#
|
||||
def tasks_today
|
||||
@tasks.select { |task| task.is_today }
|
||||
end
|
||||
|
||||
# Returns all the tasks that are due tomorrow
|
||||
#
|
||||
# @return [Array<WorkingClass::Task>] an Array with the tasks due tomorrow
|
||||
@ -53,5 +61,6 @@ module WorkingClass
|
||||
@tasks.select { |task| !task.is_finished }
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
module WorkingClass
|
||||
# The version of the gem.
|
||||
# We use semantic versioning
|
||||
VERSION = "0.1.1"
|
||||
VERSION = "0.2.1"
|
||||
end
|
||||
|
@ -61,6 +61,24 @@ class TaskTest < Minitest::Test
|
||||
assert(task.is_upcoming)
|
||||
end
|
||||
|
||||
def test_is_today
|
||||
task = Task.new "Be a WUUH Girl", :date => Date.today
|
||||
|
||||
assert(task.is_today)
|
||||
end
|
||||
|
||||
def test_is_today_without_a_date
|
||||
task = Task.new "Never be a WUUH Girl"
|
||||
|
||||
assert(!task.is_today)
|
||||
end
|
||||
|
||||
def test_is_today_with_future_date
|
||||
task = Task.new "Never be a WUUH Girl again", :date => Date.today + 1
|
||||
|
||||
assert(!task.is_today)
|
||||
end
|
||||
|
||||
def test_is_tomorrow
|
||||
task = Task.new "Eat chips", :date => Date.today + 1
|
||||
|
||||
@ -92,7 +110,6 @@ class TaskTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_alias_methods
|
||||
|
||||
task = Task.new "my awesome task"
|
||||
|
||||
assert_respond_to(task, :is_finished?)
|
||||
@ -103,6 +120,9 @@ class TaskTest < Minitest::Test
|
||||
|
||||
assert_respond_to(task, :is_upcoming?)
|
||||
assert_respond_to(task, :upcoming?)
|
||||
|
||||
assert_respond_to(task, :is_today?)
|
||||
assert_respond_to(task, :today?)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -65,5 +65,17 @@ class TasklistTest < Minitest::Test
|
||||
assert_equal(expected, tasklist.unfinished_tasks)
|
||||
end
|
||||
|
||||
def test_tasks_today
|
||||
task_1 = Task.new("Task 1", :is_finished => true)
|
||||
task_2 = Task.new("Task 2", :date => Date.today)
|
||||
task_3 = Task.new("Task 3", :date => Date.today + 1)
|
||||
task_4 = Task.new("Task 4", :is_finished => true)
|
||||
|
||||
tasks = [task_1, task_2, task_3, task_4]
|
||||
|
||||
tasklist = Tasklist.new("example_task_list", tasks)
|
||||
expected = [task_2]
|
||||
|
||||
assert_equal(expected, tasklist.tasks_today)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user