From c349894480fc72a43d080457e106aa35e85b7ca1 Mon Sep 17 00:00:00 2001 From: Luis Hurtado Date: Mon, 22 Dec 2008 09:46:14 -0500 Subject: [PATCH] Creation of AR objects support custom updated_at and updated_on attributes. --- activerecord/lib/active_record/timestamp.rb | 4 ++-- activerecord/test/cases/base_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index a9e0efa..8dbe80a 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -23,8 +23,8 @@ module ActiveRecord write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil? write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil? - write_attribute('updated_at', t) if respond_to?(:updated_at) - write_attribute('updated_on', t) if respond_to?(:updated_on) + write_attribute('updated_at', t) if respond_to?(:updated_at) && updated_at.nil? + write_attribute('updated_on', t) if respond_to?(:updated_on) && updated_on.nil? end create_without_timestamps end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 5f54931..ce27357 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -2071,6 +2071,14 @@ class BasicsTest < ActiveRecord::TestCase ActiveRecord::Base.logger = original_logger end + def test_create_with_custom_timestamps + custom_datetime = 1.hour.ago.beginning_of_day + %w(created_at created_on updated_at updated_on).each do |attr| + parrot = LiveParrot.create(:name => "colombian", attr => custom_datetime) + assert_equal custom_datetime, parrot[attr] + end + end + private def with_kcode(kcode) if RUBY_VERSION < '1.9' -- 1.5.5.1