Running timers page with view/stop permissions

- New top-menu page listing running timers: owner, issue, project,
  activity, start time, time on this run and entry total, oldest first;
  refreshes every minute
- Role permissions "View running timers" and "Stop other users' timers",
  checked against each timer's project; users can always stop their own
- A timer can be stopped at an earlier time (when the person left):
  hours logged after it are taken off the entry, and the comment notes
  who stopped it and when
- Timers now record when they were started (session_started_at); timers
  running from before show "unknown" until restarted
- Integration tests for permissions, project scoping and stopping; unit
  tests for Timer#stop_for

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-29 07:06:08 -04:00
1 parent 626db60658
commit 78f53d5d5a
11 files changed
+399 -1

No files matched your search

+32
View File
@@ -168,4 +168,36 @@ class TimerTest < ActiveSupport::TestCase
assert_no_enqueued_jobs
assert_equal hours, @time_entry.reload.hours
end
test "stop_for trims hours logged after the chosen stop time" do
hours = @time_entry.hours
@timer.start @time_entry
data[:started_at] = data[:session_started_at] = 3.hours.ago.to_i
@timer.save
@timer.update # saves the 3 hours, as the server does every minute
kept = @timer.stop_for(at: 2.hours.ago, by: User.find(2))
assert_in_delta 1.0, kept, 0.01
assert_in_delta hours + 1, @time_entry.reload.hours, 0.01
assert_includes @time_entry.comments, 'Timer stopped by'
refute Stopwatch::Timer.new(User.find(@user.id)).running?
end
test "stop_for never moves the stop time outside the run" do
hours = @time_entry.hours
@timer.start @time_entry
data[:started_at] = data[:session_started_at] = 1.hour.ago.to_i
@timer.save
@timer.stop_for(at: 1.day.from_now) # later than now: stops now
assert_in_delta hours + 1, @time_entry.reload.hours, 0.01
end
test "stop_for by the owner adds no note" do
@timer.start @time_entry
@timer.stop_for(by: @user)
refute_includes @time_entry.reload.comments.to_s, 'Timer stopped by'
end
end