Skip to content

Commit

Permalink
Merge pull request #2801 from jeremyevans/patch-1
Browse files Browse the repository at this point in the history
Fix obviously breakage of Time.=== for Time subclasses
  • Loading branch information
jeremy committed Oct 3, 2011
1 parent 2db49c5 commit 5a9e79b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Time
class << self class << self
# Overriding case equality method so that it returns true for ActiveSupport::TimeWithZone instances # Overriding case equality method so that it returns true for ActiveSupport::TimeWithZone instances
def ===(other) def ===(other)
other.is_a?(::Time) super || (self == Time && other.is_a?(ActiveSupport::TimeWithZone))
end end


# Return the number of days in the given month. # Return the number of days in the given month.
Expand Down
3 changes: 3 additions & 0 deletions activesupport/test/core_ext/time_ext_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -764,7 +764,10 @@ def test_time_created_with_local_constructor_cannot_represent_times_during_hour_
def test_case_equality def test_case_equality
assert Time === Time.utc(2000) assert Time === Time.utc(2000)
assert Time === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) assert Time === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC'])
assert Time === Class.new(Time).utc(2000)
assert_equal false, Time === DateTime.civil(2000) assert_equal false, Time === DateTime.civil(2000)
assert_equal false, Class.new(Time) === Time.utc(2000)
assert_equal false, Class.new(Time) === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC'])
end end


protected protected
Expand Down

0 comments on commit 5a9e79b

Please sign in to comment.