public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
ActiveRecord time zone aware attributes: blank string is treated as nil 
when assigned to writer
gbuesing (author)
Thu May 08 18:31:54 -0700 2008
commit  328fada610aa9128386bc4b372d3e0b68aede945
tree    2499b812446d42b2a15de1b5f152771c27db445d
parent  eb5b93be74ed3eca925c1ab9bd4739919ae39a41
...
179
180
181
182
183
184
 
 
185
 
186
187
188
...
179
180
181
 
 
 
182
183
184
185
186
187
188
0
@@ -179,10 +179,10 @@
0
         def define_write_method_for_time_zone_conversion(attr_name)
0
           method_body = <<-EOV
0
             def #{attr_name}=(time)
0
- if time
0
- time = Time.zone.parse(time) rescue time unless time.acts_like?(:time)
0
- time = time.in_time_zone if time.acts_like?(:time)
0
+ unless time.blank? || time.acts_like?(:time)
0
+ time = time.is_a?(String) ? Time.zone.parse(time) : time.to_time rescue time
0
               end
0
+ time = time.in_time_zone rescue nil if time
0
               write_attribute(:#{attr_name}, time)
0
             end
0
           EOV
...
186
187
188
 
 
 
 
 
 
 
 
189
190
191
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
0
@@ -186,6 +186,14 @@
0
       end
0
     end
0
   end
0
+
0
+ def test_setting_time_zone_aware_attribute_to_blank_string_returns_nil
0
+ in_time_zone "Pacific Time (US & Canada)" do
0
+ record = @target.new
0
+ record.written_on = ' '
0
+ assert_nil record.written_on
0
+ end
0
+ end
0
 
0
   def test_setting_time_zone_aware_attribute_interprets_time_zone_unaware_string_in_time_zone
0
     time_string = 'Tue Jan 01 00:00:00 2008'

Comments

    No one has commented yet.