Skip to content
This repository
Browse code

Add :nsec format only for Ruby 1.9

Ruby 1.8 does not support this format in Time, so the format will only
be added to the available date formats on Ruby 1.9. Changelog entry was
changed to explain that as well.
  • Loading branch information...
commit 64281fb6e742fddd4a1f67abfe5554a84349e8b7 1 parent 87a7e87
Carlos Antonio da Silva authored December 11, 2012
1  activerecord/CHANGELOG.md
Source Rendered
@@ -8,6 +8,7 @@
8 8
     *Rafael Mendonça França*
9 9
 
10 10
 *   Add `:nsec` date format. This can be used to improve the precision of cache key.
  11
+    Please note that this format only works with Ruby 1.9, Ruby 1.8 will ignore it completely.
11 12
 
12 13
     *Jamie Gaskins*
13 14
 
4  activerecord/test/cases/base_test.rb
@@ -2172,11 +2172,15 @@ def test_cache_key_format_for_existing_record_with_updated_at
2172 2172
   end
2173 2173
 
2174 2174
   def test_cache_key_format_for_existing_record_with_updated_at_1
  2175
+    return skip "Only in Ruby 1.9" if RUBY_VERSION < '1.9'
  2176
+
2175 2177
     dev = CachedDeveloper.first
2176 2178
     assert_equal "cached_developers/#{dev.id}-#{dev.updated_at.utc.to_s(:nsec)}", dev.cache_key
2177 2179
   end
2178 2180
 
2179 2181
   def test_cache_key_changes_when_child_touched
  2182
+    return skip "Only in Ruby 1.9" if RUBY_VERSION < '1.9'
  2183
+
2180 2184
     old_timestamp_format = Car.cache_timestamp_format
2181 2185
     Car.cache_timestamp_format = :nsec
2182 2186
     car = Car.create
3  activesupport/lib/active_support/core_ext/time/conversions.rb
@@ -6,7 +6,6 @@ class Time
6 6
   DATE_FORMATS = {
7 7
     :db           => "%Y-%m-%d %H:%M:%S",
8 8
     :number       => "%Y%m%d%H%M%S",
9  
-    :nsec         => '%Y%m%d%H%M%S%9N',
10 9
     :time         => "%H:%M",
11 10
     :short        => "%d %b %H:%M",
12 11
     :long         => "%B %d, %Y %H:%M",
@@ -14,6 +13,8 @@ class Time
14 13
     :rfc822       => lambda { |time| time.strftime("%a, %d %b %Y %H:%M:%S #{time.formatted_offset(false)}") }
15 14
   }
16 15
 
  16
+  DATE_FORMATS[:nsec] = '%Y%m%d%H%M%S%9N' if RUBY_VERSION >= '1.9'
  17
+
17 18
   # Converts to a formatted string. See DATE_FORMATS for builtin formats.
18 19
   #
19 20
   # This method is aliased to <tt>to_s</tt>.
18  activesupport/test/core_ext/time_ext_test.rb
@@ -539,15 +539,15 @@ def test_next_week_near_daylight_end
539 539
 
540 540
   def test_to_s
541 541
     time = Time.utc(2005, 2, 21, 17, 44, 30.12345678901)
542  
-    assert_equal time.to_default_s,                 time.to_s
543  
-    assert_equal time.to_default_s,                 time.to_s(:doesnt_exist)
544  
-    assert_equal "2005-02-21 17:44:30",             time.to_s(:db)
545  
-    assert_equal "21 Feb 17:44",                    time.to_s(:short)
546  
-    assert_equal "17:44",                           time.to_s(:time)
547  
-    assert_equal "20050221174430",                  time.to_s(:number)
548  
-    assert_equal "20050221174430123456789",         time.to_s(:nsec)
549  
-    assert_equal "February 21, 2005 17:44",         time.to_s(:long)
550  
-    assert_equal "February 21st, 2005 17:44",       time.to_s(:long_ordinal)
  542
+    assert_equal time.to_default_s,           time.to_s
  543
+    assert_equal time.to_default_s,           time.to_s(:doesnt_exist)
  544
+    assert_equal "2005-02-21 17:44:30",       time.to_s(:db)
  545
+    assert_equal "21 Feb 17:44",              time.to_s(:short)
  546
+    assert_equal "17:44",                     time.to_s(:time)
  547
+    assert_equal "20050221174430",            time.to_s(:number)
  548
+    assert_equal "20050221174430123456789",   time.to_s(:nsec) if RUBY_VERSION >= '1.9'
  549
+    assert_equal "February 21, 2005 17:44",   time.to_s(:long)
  550
+    assert_equal "February 21st, 2005 17:44", time.to_s(:long_ordinal)
551 551
     with_env_tz "UTC" do
552 552
       assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822)
553 553
     end

0 notes on commit 64281fb

Please sign in to comment.
Something went wrong with that request. Please try again.