Skip to content

Commit 08b3ec7

Browse files
committed
Fix eager loading: name the file after its constant
The eager-load gate caught this on its own author: the file was field_format.rb while the class is DatetimeFormat, so Zeitwerk expected RedmineIssueDatetime::FieldFormat and a production boot would have died with a NameError. Every test passed, because test and development load lazily - exactly the gap the gate exists for, and the same shape as karida-org/redmine_gtt_sync#81. Renamed to datetime_format.rb, with a comment so the next person does not reintroduce it. Also restores the previous User.current in the test teardown rather than assuming it was nil.
1 parent b12b41a commit 08b3ec7

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/redmine_issue_datetime.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require_relative 'redmine_issue_datetime/drift_check'
2-
require_relative 'redmine_issue_datetime/field_format'
2+
require_relative 'redmine_issue_datetime/datetime_format'
33
require_relative 'redmine_issue_datetime/issue_extension'
44
require_relative 'redmine_issue_datetime/issue_query_extension'
55
require_relative 'redmine_issue_datetime/hooks'

lib/redmine_issue_datetime/field_format.rb renamed to lib/redmine_issue_datetime/datetime_format.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ module RedmineIssueDatetime
1212
# it keeps ISO strings sortable as plain strings so ordering needs no special
1313
# casing, and it is consistent with this plugin showing one clock for everyone
1414
# rather than converting per viewer.
15+
# Named DatetimeFormat in datetime_format.rb on purpose: Redmine adds every
16+
# plugin's lib/ as an eager-load path, so Zeitwerk derives the constant from
17+
# the filename. A mismatch here passes every test (test and development load
18+
# lazily) and then kills a production boot with a NameError.
1519
class DatetimeFormat < Redmine::FieldFormat::Unbounded
1620
add 'datetime'
1721
self.form_partial = 'custom_fields/formats/datetime'

test/unit/datetime_format_test.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,18 @@ def setup
8585
# Values are shown on one clock for everyone, so formatting must not follow the
8686
# viewer's own time zone the way Redmine's format_time helper would.
8787
test 'formatting does not follow the viewer time zone' do
88+
# Captured before anything that can raise, so the ensure block always
89+
# restores rather than assuming what the surrounding state was.
90+
previous_user = User.current
8891
user = User.find(2)
89-
original = user.pref.time_zone
92+
original_zone = user.pref.time_zone
9093
User.current = user
9194
user.pref.update(time_zone: 'UTC')
9295

9396
assert_includes @field.format.formatted_value(nil, @field, '2026-08-03T09:15'), '09:15'
9497
ensure
95-
user&.pref&.update(time_zone: original)
96-
User.current = nil
98+
user&.pref&.update(time_zone: original_zone)
99+
User.current = previous_user
97100
end
98101

99102
test 'formatting a blank value yields an empty string, not an error' do

0 commit comments

Comments
 (0)