aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-09 08:37:05 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-09 08:37:05 +0000
commit300421785532b78f719a241843206e210bb7cc9d (patch)
treef0587ac1144f235b9706a42aa1f9203c49e40378 /activerecord
parente5cc729b18c13bb523732d775c8deaa58bbbe390 (diff)
downloadrails-300421785532b78f719a241843206e210bb7cc9d.tar.gz
rails-300421785532b78f719a241843206e210bb7cc9d.tar.bz2
rails-300421785532b78f719a241843206e210bb7cc9d.zip
Fixed that the SQL Server adapter would sometimes return DBI::Timestamp objects instead of Time #2127 [Tom Ward]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2169 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb1
-rwxr-xr-xactiverecord/test/associations_test.rb8
3 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index e6d6c78de4..677cb46f50 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that the SQL Server adapter would sometimes return DBI::Timestamp objects instead of Time #2127 [Tom Ward]
+
* Added the instance methods #root and #ancestors on acts_as_tree and fixed siblings to not include the current node #2142, #2140 [coffee2code]
* Fixed that Active Record would call SHOW FIELDS twice (or more) for the same model when the cached results were available #1947 [sd@notso.net]
diff --git a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
index 7d4c00b85d..2786aa2119 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -332,6 +332,7 @@ module ActiveRecord
record = {}
row.column_names.each do |col|
record[col] = row[col]
+ record[col] = record[col].to_time if record[col].is_a? DBI::Timestamp
end
rows << record
end
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index fd4bd5cda8..4eb6216dda 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -1001,7 +1001,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
# SQL Server doesn't have a separate column type just for dates,
# so the time is in the string and incorrectly formatted
if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
- kenReloaded.projects.each { |prj| assert_equal(sqlnow, prj.joined_on.to_s) }
+ kenReloaded.projects.each { |prj| assert_equal(sqlnow, prj.joined_on.strftime("%Y/%m/%d 00:00:00")) }
else
kenReloaded.projects.each { |prj| assert_equal(now.to_s, prj.joined_on.to_s) }
end
@@ -1095,7 +1095,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
# SQL Server doesn't have a separate column type just for dates,
# so the time is in the string and incorrectly formatted
if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
- assert_equal Time.mktime(2004, 10, 10).strftime("%Y/%m/%d 00:00:00"), Developer.find(1).projects.first.joined_on.to_s
+ assert_equal Time.mktime(2004, 10, 10).strftime("%Y/%m/%d 00:00:00"), Developer.find(1).projects.first.joined_on.strftime("%Y/%m/%d 00:00:00")
else
assert_equal Date.new(2004, 10, 10).to_s, Developer.find(1).projects.first.joined_on.to_s
end
@@ -1116,8 +1116,8 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
# SQL Server doesn't have a separate column type just for dates,
# so the time is in the string and incorrectly formatted
if ActiveRecord::ConnectionAdapters.const_defined? :SQLServerAdapter and ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
- assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s
- assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s
+ assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.strftime("%Y/%m/%d 00:00:00")
+ assert_equal Time.now.strftime("%Y/%m/%d 00:00:00"), developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.strftime("%Y/%m/%d 00:00:00")
else
assert_equal Date.today.to_s, jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s
assert_equal Date.today.to_s, developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on.to_s