Permalink
Browse files

Fix PostgreSQL TIMESTAMP WITH TIME ZONE to return ActiveSupport::Time

In an AR model a timestamptz attribute would return a ruby string and AR
tests did not check for any type casting.  Previous tests would pass
only because an assert_equal was being used on a Time.utc object, which
will parse the right side of the eq to a valid Time instance for
comparision.

switch to test instance of Time instead of ActiveSupport::TimeWithZone
  • Loading branch information...
1 parent b49a2a7 commit 2cc09441c2de57b024b11ba666ba1e72c2b20cfe @troyk troyk committed Mar 1, 2013
View
5 activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Postgresql timestamp with time zone (timestamptz) datatype now returns a
+ ActiveSupport::TimeWithZone instance instead of a string
+
+ *Troy Kruthoff*
+
* Added support for creating a table via Rails migration generator.
For example,
View
5 activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
@@ -317,10 +317,6 @@ def self.registered_type?(name)
alias_type 'macaddr', 'text'
alias_type 'uuid', 'text'
- # FIXME: I don't think this is correct. We should probably be returning a parsed date,
- # but the tests pass with a string returned.
- register_type 'timestamptz', OID::Identity.new
-
register_type 'money', OID::Money.new
register_type 'bytea', OID::Bytea.new
register_type 'bool', OID::Boolean.new
@@ -329,6 +325,7 @@ def self.registered_type?(name)
alias_type 'float8', 'float4'
register_type 'timestamp', OID::Timestamp.new
+ register_type 'timestamptz', OID::Timestamp.new
register_type 'date', OID::Date.new
register_type 'time', OID::Time.new
View
2 activerecord/test/cases/adapters/postgresql/datatype_test.rb
@@ -573,6 +573,7 @@ def test_timestamp_with_zone_values_with_rails_time_zone_support
@first_timestamp_with_zone = PostgresqlTimestampWithZone.find(1)
assert_equal Time.utc(2010,1,1, 11,0,0), @first_timestamp_with_zone.time
+ assert_instance_of Time, @first_timestamp_with_zone.time
ensure
ActiveRecord::Base.default_timezone = old_default_tz
ActiveRecord::Base.time_zone_aware_attributes = old_tz
@@ -590,6 +591,7 @@ def test_timestamp_with_zone_values_without_rails_time_zone_support
@first_timestamp_with_zone = PostgresqlTimestampWithZone.find(1)
assert_equal Time.utc(2010,1,1, 11,0,0), @first_timestamp_with_zone.time
+ assert_instance_of Time, @first_timestamp_with_zone.time
ensure
ActiveRecord::Base.default_timezone = old_default_tz
ActiveRecord::Base.time_zone_aware_attributes = old_tz

0 comments on commit 2cc0944

Please sign in to comment.