Skip to content

Commit

Permalink
Ensure of Model#create support custom updated_at and updated_on attri…
Browse files Browse the repository at this point in the history
…butes [#1612 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
Luis Hurtado authored and lifo committed Dec 22, 2008
1 parent 70456ae commit 63aac33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/timestamp.rb
Expand Up @@ -23,8 +23,8 @@ def create_with_timestamps #:nodoc:
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
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -16,6 +16,7 @@
require 'models/comment'
require 'models/minimalistic'
require 'models/warehouse_thing'
require 'models/parrot'
require 'rexml/document'

class Category < ActiveRecord::Base; end
Expand Down Expand Up @@ -2071,6 +2072,15 @@ def test_benchmark_with_use_silence
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 |attribute|
parrot = LiveParrot.create(:name => "colombian", attribute => custom_datetime)
assert_equal custom_datetime, parrot[attribute]
end
end

private
def with_kcode(kcode)
if RUBY_VERSION < '1.9'
Expand Down

0 comments on commit 63aac33

Please sign in to comment.