mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-21 00:16:09 +01:00
Refactor the calculation for staleness
Provide the number of days that the todo was stale instead of a class name to use in the view. We'll use the number of days stale in the helper to determine the class name
This commit is contained in:
parent
8dfbac0fe8
commit
43275e064e
2 changed files with 9 additions and 27 deletions
|
|
@ -1,18 +1,10 @@
|
|||
require 'active_support/all'
|
||||
|
||||
class Staleness
|
||||
SECONDS_PER_DAY = 86400
|
||||
def self.days_stale(item, current_user)
|
||||
if item.due || item.completed?
|
||||
return ""
|
||||
elsif item.created_at < current_user.time - (current_user.prefs.staleness_starts * 3).days
|
||||
return " stale_l3"
|
||||
elsif item.created_at < current_user.time - (current_user.prefs.staleness_starts * 2).days
|
||||
return " stale_l2"
|
||||
elsif item.created_at < current_user.time - (current_user.prefs.staleness_starts).days
|
||||
return " stale_l1"
|
||||
else
|
||||
return ""
|
||||
end
|
||||
return 0 if item.due || item.completed?
|
||||
(current_user.time - item.created_at).to_i / SECONDS_PER_DAY
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -40,32 +40,22 @@ class StalenessTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_item_with_due_date_is_not_stale_ever
|
||||
todo = FakeTask.new(day24, false, now)
|
||||
assert_equal "", Staleness.days_stale(todo, @current_user)
|
||||
todo = FakeTask.new(now, false, day24)
|
||||
assert_equal 0, Staleness.days_stale(todo, @current_user)
|
||||
end
|
||||
|
||||
def test_complete_item_is_not_stale
|
||||
todo = FakeTask.new(day16, true, day24)
|
||||
assert_equal "", Staleness.days_stale(todo, @current_user)
|
||||
assert_equal 0, Staleness.days_stale(todo, @current_user)
|
||||
end
|
||||
|
||||
def test_young_item_is_not_stale
|
||||
todo = FakeTask.new(nil, false, now)
|
||||
assert_equal "", Staleness.days_stale(todo, @current_user)
|
||||
assert_equal 0, Staleness.days_stale(todo, @current_user)
|
||||
end
|
||||
|
||||
def test_staleness_level_one
|
||||
def test_todo_staleness_calculation
|
||||
todo = FakeTask.new(nil, false, day8)
|
||||
assert_equal " stale_l1", Staleness.days_stale(todo, @current_user)
|
||||
end
|
||||
|
||||
def test_staleness_level_two
|
||||
todo = FakeTask.new(nil, false, day16)
|
||||
assert_equal " stale_l2", Staleness.days_stale(todo, @current_user)
|
||||
end
|
||||
|
||||
def test_staleness_level_three
|
||||
todo = FakeTask.new(nil, false, day24)
|
||||
assert_equal " stale_l3", Staleness.days_stale(todo, @current_user)
|
||||
assert_equal 8, Staleness.days_stale(todo, @current_user)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue