public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Ensure of Model#create support custom updated_at and updated_on attributes 
[#1612 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
luishurtado (author)
Mon Dec 22 07:18:43 -0800 2008
lifo (committer)
Mon Dec 22 07:19:33 -0800 2008
commit  63aac338332a06d3c9e28dde7954679703ec7620
tree    29444858c43d6f3a22e9f50ed5e2252ecb6e862a
parent  70456aed31ae64b36563fc5d32ac114e0a095231
...
23
24
25
26
27
 
 
28
29
30
...
23
24
25
 
 
26
27
28
29
30
0
@@ -23,8 +23,8 @@ module ActiveRecord
0
           write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil?
0
           write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil?
0
 
0
-          write_attribute('updated_at', t) if respond_to?(:updated_at)
0
-          write_attribute('updated_on', t) if respond_to?(:updated_on)
0
+          write_attribute('updated_at', t) if respond_to?(:updated_at) && updated_at.nil?
0
+          write_attribute('updated_on', t) if respond_to?(:updated_on) && updated_on.nil?
0
         end
0
         create_without_timestamps
0
       end
...
16
17
18
 
19
20
21
...
2071
2072
2073
 
 
 
 
 
 
 
 
 
2074
2075
2076
...
16
17
18
19
20
21
22
...
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
0
@@ -16,6 +16,7 @@ require 'models/post'
0
 require 'models/comment'
0
 require 'models/minimalistic'
0
 require 'models/warehouse_thing'
0
+require 'models/parrot'
0
 require 'rexml/document'
0
 
0
 class Category < ActiveRecord::Base; end
0
@@ -2071,6 +2072,15 @@ class BasicsTest < ActiveRecord::TestCase
0
     ActiveRecord::Base.logger = original_logger
0
   end
0
 
0
+  def test_create_with_custom_timestamps
0
+    custom_datetime = 1.hour.ago.beginning_of_day
0
+
0
+    %w(created_at created_on updated_at updated_on).each do |attribute|
0
+      parrot = LiveParrot.create(:name => "colombian", attribute => custom_datetime)
0
+      assert_equal custom_datetime, parrot[attribute]
0
+    end
0
+  end
0
+
0
   private
0
     def with_kcode(kcode)
0
       if RUBY_VERSION < '1.9'

Comments