Skip to content

Commit dfe3c9e

Browse files
justin808claude
andcommitted
Fix edge case and timing issues in locale generation
1. Fixed critical edge case in files_are_outdated: - Changed to return false when locale_files is empty - Prevents generation of empty translation files when no source YAML exists - Previously returned true (outdated), which would trigger empty generation 2. Improved user message clarity: - Updated message to show exact rake task syntax - Changed from "Use force=true" to "Use 'rake react_on_rails:locale force=true'" - Helps users understand how to pass the parameter correctly 3. Fixed timing-dependent test flake: - Added 10ms sleep in spec to ensure different timestamps on fast filesystems - Prevents CI failures where file regeneration happens within same timestamp - Test was failing in CI due to mtime equality instead of greater-than All tests pass and RuboCop clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f2813a9 commit dfe3c9e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/react_on_rails/locales/base.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def initialize(force: false)
4040
return if i18n_dir.nil?
4141

4242
if !force && !obsolete?
43-
puts "Locale files are up to date, skipping generation. Use force=true to regenerate."
43+
puts "Locale files are up to date, skipping generation. " \
44+
"Use 'rake react_on_rails:locale force=true' to force regeneration."
4445
return
4546
end
4647

@@ -64,7 +65,7 @@ def exist_files
6465
end
6566

6667
def files_are_outdated
67-
return true if locale_files.empty?
68+
return false if locale_files.empty? # No source files = nothing to generate
6869

6970
latest_yml = locale_files.map { |file| File.mtime(file) }.max
7071
earliest = exist_files.map { |file| File.mtime(file) }.min

spec/react_on_rails/locales_to_js_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ module ReactOnRails
5555
# Get initial mtime after first generation
5656
initial_mtime = File.mtime(translations_path)
5757

58+
# Sleep to ensure different timestamp on fast filesystems
59+
sleep 0.01
60+
5861
# Touch files to make them newer than YAML (up-to-date)
5962
future_time = Time.current + 1.minute
6063
FileUtils.touch(translations_path, mtime: future_time)

0 commit comments

Comments
 (0)