Skip to content

Commit

Permalink
Cache the current time
Browse files Browse the repository at this point in the history
  • Loading branch information
brendon committed Oct 29, 2016
1 parent d5debe1 commit 8575e56
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions test/test_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,10 @@ def setup
end
end

def now
@now ||= Time.current
end

def yesterday
@yesterday ||= 1.day.ago
end
Expand All @@ -680,10 +684,10 @@ def updated_ats
end

def test_moving_item_lower_touches_self_and_lower_item
Timecop.freeze(Time.current) do
Timecop.freeze(now) do
ListMixin.first.move_lower
updated_ats[0..1].each do |updated_at|
assert_equal updated_at, Time.current
assert_equal updated_at, now
end
updated_ats[2..3].each do |updated_at|
assert_equal updated_at, yesterday
Expand All @@ -692,10 +696,10 @@ def test_moving_item_lower_touches_self_and_lower_item
end

def test_moving_item_higher_touches_self_and_higher_item
Timecop.freeze(Time.current) do
Timecop.freeze(now) do
ListMixin.all.second.move_higher
updated_ats[0..1].each do |updated_at|
assert_equal updated_at, Time.current
assert_equal updated_at, now
end
updated_ats[2..3].each do |updated_at|
assert_equal updated_at, yesterday
Expand All @@ -704,31 +708,31 @@ def test_moving_item_higher_touches_self_and_higher_item
end

def test_moving_item_to_bottom_touches_all_other_items
Timecop.freeze(Time.current) do
Timecop.freeze(now) do
ListMixin.first.move_to_bottom
updated_ats.each do |updated_at|
assert_equal updated_at, Time.current
assert_equal updated_at, now
end
end
end

def test_moving_item_to_top_touches_all_other_items
Timecop.freeze(Time.current) do
Timecop.freeze(now) do
ListMixin.last.move_to_top
updated_ats.each do |updated_at|
assert_equal updated_at, Time.current
assert_equal updated_at, now
end
end
end

def test_removing_item_touches_all_lower_items
Timecop.freeze(Time.current) do
Timecop.freeze(now) do
ListMixin.all.third.remove_from_list
updated_ats[0..1].each do |updated_at|
assert_equal updated_at, yesterday
end
updated_ats[2..2].each do |updated_at|
assert_equal updated_at, Time.current
assert_equal updated_at, now
end
end
end
Expand Down

0 comments on commit 8575e56

Please sign in to comment.