1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Explicitly set Topic model last_read attribute as Date value when Oracle enhanced adapter is used

(otherwise some tests are failing which assume that this attribute will have Date value)
This commit is contained in:
Raimonds Simanovskis 2009-08-10 17:25:53 +03:00
parent eec90bab28
commit 8136230cca
2 changed files with 10 additions and 3 deletions

View file

@ -430,14 +430,14 @@ class BasicsTest < ActiveRecord::TestCase
end end
def test_preserving_date_objects def test_preserving_date_objects
if current_adapter?(:SybaseAdapter, :OracleAdapter) if current_adapter?(:SybaseAdapter)
# Sybase ctlib does not (yet?) support the date type; use datetime instead. # Sybase ctlib does not (yet?) support the date type; use datetime instead.
# Oracle treats all dates/times as Time.
assert_kind_of( assert_kind_of(
Time, Topic.find(1).last_read, Time, Topic.find(1).last_read,
"The last_read attribute should be of the Time class" "The last_read attribute should be of the Time class"
) )
else else
# Oracle enhanced adapter allows to define Date attributes in model class (see topic.rb)
assert_kind_of( assert_kind_of(
Date, Topic.find(1).last_read, Date, Topic.find(1).last_read,
"The last_read attribute should be of the Date class" "The last_read attribute should be of the Date class"
@ -2125,10 +2125,11 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal "integer", xml.elements["//parent-id"].attributes['type'] assert_equal "integer", xml.elements["//parent-id"].attributes['type']
assert_equal "true", xml.elements["//parent-id"].attributes['nil'] assert_equal "true", xml.elements["//parent-id"].attributes['nil']
if current_adapter?(:SybaseAdapter, :OracleAdapter) if current_adapter?(:SybaseAdapter)
assert_equal last_read_in_current_timezone, xml.elements["//last-read"].text assert_equal last_read_in_current_timezone, xml.elements["//last-read"].text
assert_equal "datetime" , xml.elements["//last-read"].attributes['type'] assert_equal "datetime" , xml.elements["//last-read"].attributes['type']
else else
# Oracle enhanced adapter allows to define Date attributes in model class (see topic.rb)
assert_equal "2004-04-15", xml.elements["//last-read"].text assert_equal "2004-04-15", xml.elements["//last-read"].text
assert_equal "date" , xml.elements["//last-read"].attributes['type'] assert_equal "date" , xml.elements["//last-read"].attributes['type']
end end

View file

@ -43,6 +43,12 @@ class Topic < ActiveRecord::Base
before_create :default_written_on before_create :default_written_on
before_destroy :destroy_children before_destroy :destroy_children
# Explicitly define as :date column so that returned Oracle DATE values would be typecasted to Date and not Time.
# Some tests depend on assumption that this attribute will have Date values.
if current_adapter?(:OracleEnhancedAdapter)
set_date_columns :last_read
end
def parent def parent
Topic.find(parent_id) Topic.find(parent_id)
end end