Created
March 28, 2011 10:33
-
-
Save chrisroos/890257 to your computer and use it in GitHub Desktop.
A test that attempts to ensure we don't run into problems with daylight savings. Credit for the test goes to James Mead.
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
require 'test_helper' | |
class TimeZoneTest < ActiveSupport::TestCase | |
should "only use instances of TimeWithZone, not instances of Time" 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)}).any? | |
end | |
match | |
end | |
assert_equal [], matching_files - [File.expand_path(__FILE__)], %{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, etc.} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment