+ freeze_time do
+ block = create(:user_block, :needs_view, :zero_hour, :user => user)
+ assert block.needs_view
+ assert_nil block.deactivates_at
+
+ travel 1.hour
+
+ get user_block_path(block)
+ assert_response :success
+ block.reload
+ assert_not block.needs_view
+ assert_equal Time.now.utc, block.deactivates_at
+
+ travel 1.hour
+
+ get user_block_path(block)
+ assert_response :success
+ block.reload
+ assert_not block.needs_view
+ assert_equal Time.now.utc - 1.hour, block.deactivates_at
+ end
+ end
+
+ ##
+ # test clearing needs_view by showing a timed block to the blocked user
+ def test_show_sets_deactivates_at_for_timed_block
+ user = create(:user)
+ session_for(user)
+
+ freeze_time do
+ block = create(:user_block, :needs_view, :created_at => Time.now.utc, :ends_at => Time.now.utc + 24.hours, :user => user)
+ assert block.needs_view
+ assert_nil block.deactivates_at
+
+ travel 1.hour
+
+ get user_block_path(block)
+ assert_response :success
+ block.reload
+ assert_not block.needs_view
+ assert_equal Time.now.utc + 23.hours, block.deactivates_at
+
+ travel 1.hour
+
+ get user_block_path(block)
+ assert_response :success
+ block.reload
+ assert_not block.needs_view
+ assert_equal Time.now.utc + 22.hours, block.deactivates_at
+
+ travel 24.hours
+
+ get user_block_path(block)
+ assert_response :success
+ block.reload
+ assert_not block.needs_view
+ assert_equal Time.now.utc - 2.hours, block.deactivates_at
+ end