public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
TimeWithZone: date part getter methods (#year #mon #day etc) are defined 
on class; no longer relying on method_missing
gbuesing (author)
Thu May 08 20:07:21 -0700 2008
commit  4f03190f262c07c1f389957ff7ae76901495d824
tree    621f5ccd85e2815f46f95bbb4b2195c879680bba
parent  618d695f1115c00ce058950af199d5d4dc06385a
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* TimeWithZone: date part getter methods (#year #mon #day etc) are defined on class; no longer relying on method_missing [Geoff Buesing]
0
+
0
 * Time.zone.parse return nil for strings with no date information [Geoff Buesing]
0
 
0
 * Time.zone.parse respects offset information in string. Resolves #105. [Scott Fleckenstein, Geoff Buesing]
...
163
164
165
 
 
 
 
 
 
 
 
166
167
168
...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
0
@@ -163,6 +163,14 @@
0
       utc.advance(options).in_time_zone(time_zone)
0
     end
0
     
0
+ %w(year mon month day mday hour min sec).each do |method_name|
0
+ class_eval <<-EOV
0
+ def #{method_name}
0
+ time.#{method_name}
0
+ end
0
+ EOV
0
+ end
0
+
0
     def usec
0
       time.respond_to?(:usec) ? time.usec : 0
0
     end
...
328
329
330
331
 
332
333
 
 
 
 
 
 
 
334
 
335
336
337
...
328
329
330
 
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
0
@@ -328,10 +328,18 @@
0
       assert_equal Time.utc(1999, 12, 31, 19), mtime.time
0
     end
0
   end
0
-
0
+
0
   def test_method_missing_with_non_time_return_value
0
     silence_warnings do # silence warnings raised by tzinfo gem
0
+ @twz.time.expects(:foo).returns('bar')
0
+ assert_equal 'bar', @twz.foo
0
+ end
0
+ end
0
+
0
+ def test_date_part_value_methods
0
+ silence_warnings do # silence warnings raised by tzinfo gem
0
       twz = ActiveSupport::TimeWithZone.new(Time.utc(1999,12,31,19,18,17,500), @time_zone)
0
+ twz.stubs(:method_missing).returns(nil) #ensure these methods are defined directly on class
0
       assert_equal 1999, twz.year
0
       assert_equal 12, twz.month
0
       assert_equal 31, twz.day

Comments

    No one has commented yet.