Skip to content

Commit

Permalink
Changed the auto-timestamping feature to use ActiveRecord::Base.defau…
Browse files Browse the repository at this point in the history
…lt_timezone instead of entertaining the parallel ActiveRecord::Base.timestamps_gmt method. The latter is now deprecated and will throw a warning on use (but still work) #710 [Jamis Buck]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@788 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Feb 24, 2005
1 parent f73f9e4 commit 4fbc3e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN*

* Changed the auto-timestamping feature to use ActiveRecord::Base.default_timezone instead of entertaining the parallel ActiveRecord::Base.timestamps_gmt method. The latter is now deprecated and will throw a warning on use (but still work) #710 [Jamis Buck]

* Added a OCI8-based Oracle adapter that has been verified to work with Oracle 8 and 9 #629 [Graham Jenkins]. Usage notes:

1. Key generation uses a sequence "rails_sequence" for all tables. (I couldn't find a simple
Expand Down
16 changes: 13 additions & 3 deletions activerecord/lib/active_record/timestamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.append_features(base) # :nodoc:
end

def create_with_timestamps #:nodoc:
t = timestamps_gmt ? Time.now.gmtime : Time.now
t = ( self.class.default_timezone == :utc ? Time.now.utc : Time.now )
write_attribute("created_at", t) if record_timestamps && respond_to?(:created_at) && created_at.nil?
write_attribute("created_on", t) if record_timestamps && respond_to?(:created_on) && created_on.nil?

Expand All @@ -30,7 +30,7 @@ def create_with_timestamps #:nodoc:
end

def update_with_timestamps #:nodoc:
t = timestamps_gmt ? Time.now.gmtime : Time.now
t = ( self.class.default_timezone == :utc ? Time.now.utc : Time.now )
write_attribute("updated_at", t) if record_timestamps && respond_to?(:updated_at)
write_attribute("updated_on", t) if record_timestamps && respond_to?(:updated_on)

Expand All @@ -44,7 +44,17 @@ class Base
# if the table has columns of either of these names. This feature is turned on by default.
@@record_timestamps = true
cattr_accessor :record_timestamps

# deprecated: use ActiveRecord::Base.default_timezone instead.
@@timestamps_gmt = false
cattr_accessor :timestamps_gmt
def self.timestamps_gmt=( gmt ) #:nodoc:
warn "timestamps_gmt= is deprecated. use default_timezone= instead"
self.default_timezone = ( gmt ? :utc : :local )
end

def self.timestamps_gmt #:nodoc:
warn "timestamps_gmt is deprecated. use default_timezone instead"
self.default_timezone == :utc
end
end
end
4 changes: 2 additions & 2 deletions activerecord/test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -709,13 +709,13 @@ def test_reload

def test_define_attr_method_with_value
k = Class.new( ActiveRecord::Base )
k.define_attr_method :table_name, "foo"
k.send(:define_attr_method, :table_name, "foo")
assert_equal "foo", k.table_name
end

def test_define_attr_method_with_block
k = Class.new( ActiveRecord::Base )
k.define_attr_method( :primary_key ) { "sys_" + original_primary_key }
k.send(:define_attr_method, :primary_key) { "sys_" + original_primary_key }
assert_equal "sys_id", k.primary_key
end

Expand Down

0 comments on commit 4fbc3e3

Please sign in to comment.