This repository has been archived by the owner on Oct 12, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also, test for inappropriate uses of time without zone. The changes to mongoid.yml need to be reflected in alphagov-deployment.
- Loading branch information
1 parent
9b37baa
commit 1261337
Showing
6 changed files
with
36 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
task :check_for_bad_time_handling do | ||
directories = Dir.glob(File.join(Rails.root, '**', '*.rb')) | ||
matching_files = directories.select do |filename| | ||
match = false | ||
File.open(filename) do |file| | ||
match = file.grep(%r{Time\.(now|utc|parse)}).any? | ||
end | ||
match | ||
end | ||
if matching_files.any? | ||
raise <<-MSG | ||
Avoid issues with daylight-savings time by always building instances of | ||
TimeWithZone and not Time. Use methods like: | ||
Time.zone.now, Time.zone.parse, n.days.ago, m.hours.from_now, etc | ||
in preference to methods like: | ||
Time.now, Time.utc, Time.parse, etc | ||
Files that contain bad Time handling: | ||
#{matching_files.join("\n ")} | ||
MSG | ||
end | ||
end |