Files
stopwatch/test/integration/running_timers_test.rb
T
rickyandClaude Opus 5.5 9c937c6d6b Closing time in local time for users without a time zone
Users without a time zone in their preferences fell back to UTC, so a 17:00 closing time stopped their
timers hours early (e.g. at noon on a US Eastern server). Like Redmine (User#today), they now get the
server's local time: for closing time, the Running timers page's "stopped at" field, and the "Timer
stopped by" note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 18:07:44 -05:00

92 lines
3.7 KiB
Ruby

require File.expand_path('../test_helper', __dir__)
class RunningTimersTest < Redmine::IntegrationTest
fixtures :projects, :users, :email_addresses, :user_preferences, :roles, :members, :member_roles,
:trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues,
:enumerations, :time_entries
setup do
@issue = Issue.find 1
@manager = User.find_by_login 'jsmith' # Manager in project 1
@worker = User.find_by_login 'dlopper' # Developer in project 1
@entry = TimeEntry.create!(project: @issue.project, issue: @issue, user: @worker, author: @worker,
spent_on: Date.today, hours: 1, activity: TimeEntryActivity.first)
timer = Stopwatch::Timer.new(@worker)
timer.start @entry
data = timer.send(:data)
data[:started_at] = data[:session_started_at] = 3.hours.ago.to_i
timer.save
Role.find(1).remove_permission!(:view_running_timers, :stop_running_timers)
Role.find(2).remove_permission!(:view_running_timers, :stop_running_timers)
end
def worker_timer
Stopwatch::Timer.new(User.find(@worker.id))
end
test "page needs the view permission" do
log_user 'jsmith', 'jsmith'
get '/stopwatch/running_timers'
assert_response 403
end
test "lists running timers without a stop button when the user can only view" do
Role.find(1).add_permission!(:view_running_timers)
log_user 'jsmith', 'jsmith'
get '/stopwatch/running_timers'
assert_response :success
assert_select "tr#stopwatch-running-timer-#{@worker.id} td.user", text: /#{@worker.name}/
assert_select "tr#stopwatch-running-timer-#{@worker.id} td.started", text: /\d/
assert_select "tr#stopwatch-running-timer-#{@worker.id} form.stopwatch-stop-form", 0
end
test "stopping someone else's timer needs the stop permission" do
Role.find(1).add_permission!(:view_running_timers)
log_user 'jsmith', 'jsmith'
post "/stopwatch/running_timers/#{@worker.id}/stop"
assert_response 403
assert worker_timer.running?
end
test "manager stops a forgotten timer at the time the person left" do
Role.find(1).add_permission!(:view_running_timers, :stop_running_timers)
log_user 'jsmith', 'jsmith'
get '/stopwatch/running_timers'
assert_select "tr#stopwatch-running-timer-#{@worker.id} form.stopwatch-stop-form"
# jsmith has no time zone, so the field is in the server's local time
left_at = 2.hours.ago.getlocal.strftime('%Y-%m-%dT%H:%M') # 1 hour after starting
post "/stopwatch/running_timers/#{@worker.id}/stop", params: { stopped_at: left_at }
assert_redirected_to '/stopwatch/running_timers'
refute worker_timer.running?
@entry.reload
assert_in_delta 2.0, @entry.hours, 0.02 # 1 hour before + 1 hour of this run
assert_includes @entry.comments, "Timer stopped by #{@manager.name}"
end
test "stopping without a time stops now" do
Role.find(1).add_permission!(:view_running_timers, :stop_running_timers)
log_user 'jsmith', 'jsmith'
post "/stopwatch/running_timers/#{@worker.id}/stop"
refute worker_timer.running?
assert_in_delta 4.0, @entry.reload.hours, 0.02
end
test "users with view permission can stop their own timer" do
Role.find(2).add_permission!(:view_running_timers)
log_user 'dlopper', 'foo'
post "/stopwatch/running_timers/#{@worker.id}/stop"
refute worker_timer.running?
refute_includes @entry.reload.comments.to_s, 'Timer stopped by'
end
test "timers in other projects are not shown" do
Role.find(1).add_permission!(:view_running_timers)
@entry.update_columns(project_id: 2, issue_id: nil) # jsmith has no view_running_timers in project 2
log_user 'jsmith', 'jsmith'
get '/stopwatch/running_timers'
assert_select "tr#stopwatch-running-timer-#{@worker.id}", 0
end
end