From 157141b2949b845e372ee703bfd6fba3ffb00415 Mon Sep 17 00:00:00 2001 From: gbuesing Date: Sun, 14 Sep 2008 23:07:48 -0500 Subject: [PATCH] TimeWithZone #wday, #yday and #to_date avoid trip through #method_missing --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/time_with_zone.rb | 2 +- activesupport/test/core_ext/time_with_zone_test.rb | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 15df4015aa..00da2a2284 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* TimeWithZone #wday, #yday and #to_date avoid trip through #method_missing [Geoff Buesing] + * Added Time, Date, DateTime and TimeWithZone #past?, #future? and #today? #720 [Clemens Kofler, Geoff Buesing] * Fixed Sri Jayawardenepura time zone to map to Asia/Colombo [Jamis Buck] diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 54cf945251..b7b8807c6d 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -231,7 +231,7 @@ module ActiveSupport end end - %w(year mon month day mday hour min sec).each do |method_name| + %w(year mon month day mday wday yday hour min sec to_date).each do |method_name| class_eval <<-EOV def #{method_name} time.#{method_name} diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index dc3dee05ce..72b540efe0 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -397,7 +397,7 @@ class TimeWithZoneTest < Test::Unit::TestCase def test_date_part_value_methods silence_warnings do # silence warnings raised by tzinfo gem twz = ActiveSupport::TimeWithZone.new(Time.utc(1999,12,31,19,18,17,500), @time_zone) - twz.stubs(:method_missing).returns(nil) #ensure these methods are defined directly on class + twz.expects(:method_missing).never assert_equal 1999, twz.year assert_equal 12, twz.month assert_equal 31, twz.day @@ -405,6 +405,8 @@ class TimeWithZoneTest < Test::Unit::TestCase assert_equal 18, twz.min assert_equal 17, twz.sec assert_equal 500, twz.usec + assert_equal 5, twz.wday + assert_equal 365, twz.yday end end end