mirror of
https://github.com/rickbarrette/stopwatch.git
synced 2026-11-17 11:50:36 -05:00
- Maximum timer length setting (default 10h): a timer that runs past it is stopped at the limit and its entry's comment is flagged, so a forgotten timer can't add a night or weekend of hours - StopwatchTimerTickJob saves a running timer's time every minute on the server (no browser needed) and stops it at the limit on time; open tabs keep saving too - Timer updates lock the user's preference row and re-read the timer, so simultaneous saves (several tabs, the job) never add time twice - Closing an issue stops timers running on it before anything else (e.g. billing) uses its time; deleting a time entry only stops the timer running on that entry - Issue timers require a visible issue; starting again moves the timer instead of raising "timer is already running" - Tests updated and extended (limit, locking, tick job, close, delete, visibility, issue context menu); CI runs on Redmine 7.0 - Upstream's German notes translated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
132 lines
3.4 KiB
Ruby
132 lines
3.4 KiB
Ruby
require File.expand_path('../test_helper', __dir__)
|
|
|
|
class TicketTimerTest < Redmine::IntegrationTest
|
|
include ActiveJob::TestHelper
|
|
|
|
fixtures :projects,
|
|
:users, :email_addresses,
|
|
:roles,
|
|
:members,
|
|
:member_roles,
|
|
:trackers,
|
|
:projects_trackers,
|
|
:enabled_modules,
|
|
:issue_statuses,
|
|
:issues,
|
|
:enumerations,
|
|
:custom_fields,
|
|
:custom_values,
|
|
:custom_fields_trackers,
|
|
:attachments
|
|
|
|
setup do
|
|
@issue = Issue.find 1
|
|
@user = User.find_by_login 'jsmith'
|
|
end
|
|
|
|
test "should create / stop / resume timer for ticket" do
|
|
log_user 'jsmith', 'jsmith'
|
|
|
|
assert_not_running
|
|
|
|
get "/issues/1"
|
|
assert_response :success
|
|
assert_select "div.contextual a", text: /start tracking/i
|
|
assert_no_difference ->{TimeEntry.count} do
|
|
post "/issues/1/timer/start", xhr: true
|
|
assert_response :success
|
|
end
|
|
assert_not_running
|
|
|
|
assert_difference ->{TimeEntry.count} do
|
|
post "/stopwatch_timers", xhr: true, params: {
|
|
time_entry: { issue_id: 1, activity_id: 9 }
|
|
}
|
|
assert_response :success
|
|
end
|
|
|
|
assert_running
|
|
|
|
get "/issues/1"
|
|
assert_select "div.contextual a", text: /stop tracking/i
|
|
assert_no_difference ->{TimeEntry.count} do
|
|
post "/issues/1/timer/stop", xhr: true
|
|
end
|
|
|
|
assert_not_running
|
|
|
|
get "/issues/1"
|
|
assert_select "div.contextual a", text: /start tracking/i
|
|
assert_no_difference ->{TimeEntry.count} do
|
|
post "/issues/1/timer/start", xhr: true
|
|
end
|
|
assert_response :success
|
|
|
|
assert_running
|
|
|
|
get "/issues/1"
|
|
assert_select "div.contextual a", text: /stop tracking/i
|
|
assert_no_difference ->{TimeEntry.count} do
|
|
post "/issues/1/timer/stop", xhr: true
|
|
end
|
|
|
|
assert_not_running
|
|
end
|
|
|
|
test "should not start a timer on an issue the user cannot see" do
|
|
log_user 'jsmith', 'jsmith'
|
|
post "/issues/999999/timer/start", xhr: true
|
|
assert_response 404
|
|
end
|
|
|
|
test "should offer start tracking in the issue context menu" do
|
|
log_user 'jsmith', 'jsmith'
|
|
get "/issues/context_menu", params: { ids: [@issue.id] }, xhr: true
|
|
assert_response :success
|
|
assert_select "a.stopwatch_issue_timer", text: /start tracking/i
|
|
end
|
|
|
|
test "should ask by default" do
|
|
log_user 'jsmith', 'jsmith'
|
|
TimeEntry.delete_all
|
|
assert_no_difference ->{TimeEntry.count} do
|
|
post "/issues/1/timer/start", xhr: true
|
|
assert_response :ok
|
|
end
|
|
end
|
|
|
|
test "should use global default actvity" do
|
|
log_user 'jsmith', 'jsmith'
|
|
TimeEntry.delete_all
|
|
with_settings plugin_stopwatch: { 'default_activity' => 'system'} do
|
|
post "/issues/1/timer/start", xhr: true
|
|
assert_response :created
|
|
end
|
|
assert te = TimeEntry.last
|
|
assert_equal 1, te.issue_id
|
|
assert_equal 10, te.activity_id
|
|
end
|
|
|
|
test "should use configured default actvity" do
|
|
log_user 'jsmith', 'jsmith'
|
|
TimeEntry.delete_all
|
|
with_settings plugin_stopwatch: { 'default_activity' => '9'} do
|
|
post "/issues/1/timer/start", xhr: true
|
|
assert_response :created
|
|
end
|
|
assert te = TimeEntry.last
|
|
assert_equal 1, te.issue_id
|
|
assert_equal 9, te.activity_id
|
|
end
|
|
|
|
private
|
|
|
|
def assert_not_running
|
|
assert_not Stopwatch::Timer.new(User.find(@user.id)).running?
|
|
end
|
|
|
|
def assert_running
|
|
assert Stopwatch::Timer.new(User.find(@user.id)).running?
|
|
end
|
|
end
|