Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 40

Show
Ignore:
Timestamp:
12/01/04 13:18:51 (4 years ago)
Author:
david
Message:

Added proper handling of time fields that are turned into Time objects with the dummy date of 2000/1/1 [HariSeldon]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r38 r40  
    11*CVS* 
     2 
     3* Added proper handling of time fields that are turned into Time objects with the dummy date of 2000/1/1 [HariSeldon] 
    24 
    35* Added reverse order of deleting fixtures, so referential keys can be maintained #247 [Tim Bates] 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb

    r35 r40  
    183183          when :datetime      then Time 
    184184          when :date          then Date 
     185         when :time          then Time 
    185186          when :text, :string then String 
    186187          when :boolean       then Object 
     
    196197          when :float    then value.to_f 
    197198          when :datetime then string_to_time(value) 
     199         when :time     then string_to_dummy_time(value) 
    198200          when :date     then string_to_date(value) 
    199201          when :boolean  then (value == "t" or value == true ? true : false) 
     
    221223        end 
    222224 
     225       def string_to_dummy_time(string) 
     226         return string if Time === string 
     227         time_array = ParseDate.parsedate(string) 
     228         # pad the resulting array with dummy date information 
     229         time_array[0] = 2000; time_array[1] = 1; time_array[2] = 1; 
     230         Time.local(*time_array) rescue nil 
     231       end 
     232 
    223233        def extract_limit(sql_type) 
    224234          $1.to_i if sql_type =~ /\((.*)\)/ 
     
    231241            when /float|double|decimal|numeric/i 
    232242              :float 
    233             when /time/i 
     243            when /datetime/i 
    234244              :datetime 
     245           when /time/i 
     246             :time 
    235247            when /date/i 
    236248              :date 
  • trunk/activerecord/test/base_test.rb

    r4 r40  
    148148      "The last_read attribute should be of the Date class" 
    149149    ) 
     150 
     151    assert_kind_of( 
     152      Time, Topic.find(1).bonus_time, 
     153      "The bonus_time attribute should be of the Time class" 
     154    ) 
    150155  end 
    151156 
     
    312317    assert_equal 1, topic.approved 
    313318    assert_nil topic.written_on 
     319    assert_nil topic.bonus_time 
    314320    assert_nil topic.last_read 
    315321     
     
    425431    topic.attributes = attributes 
    426432    assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on 
     433  end 
     434 
     435  def test_attributes_on_dummy_time 
     436    attributes = { 
     437      "bonus_time" => "5:42:00AM" 
     438    } 
     439    topic = Topic.find(1) 
     440    topic.attributes = attributes 
     441    assert_equal Time.local(2000, 1, 1, 5, 42, 0), topic.bonus_time 
    427442  end 
    428443 
  • trunk/activerecord/test/fixtures/db_definitions/mysql.sql

    r4 r40  
    2424  `author_email_address` varchar(255) default NULL, 
    2525  `written_on` datetime default NULL, 
     26  `bonus_time` time default NULL, 
    2627  `last_read` date default NULL, 
    2728  `content` text, 
  • trunk/activerecord/test/fixtures/db_definitions/postgresql.sql

    r4 r40  
    4747    author_email_address character varying(255), 
    4848    written_on timestamp without time zone, 
     49    bonus_time time, 
    4950    last_read date, 
    5051    content text, 
  • trunk/activerecord/test/fixtures/db_definitions/sqlite.sql

    r4 r40  
    2222  'author_email_address' VARCHAR(255) DEFAULT NULL, 
    2323  'written_on' DATETIME DEFAULT NULL, 
     24  'bonus_time' TIME DEFAULT NULL, 
    2425  'last_read' DATE DEFAULT NULL, 
    2526  'content' TEXT, 
  • trunk/activerecord/test/fixtures/topics/first

    r4 r40  
    44author_email_address => david@loudthinking.com 
    55written_on        => 2003-07-16 15:28 
     6bonus_time       => 12:13:14 
    67last_read        => 2004-04-15 
    78content          => Have a nice day 
  • trunk/activerecord/test/reflection_test.rb

    r4 r40  
    1616  def test_read_attribute_names 
    1717    assert_equal( 
    18       %w( id title author_name author_email_address written_on last_read content approved replies_count parent_id type ).sort, 
     18      %w( id title author_name author_email_address bonus_time written_on last_read content approved replies_count parent_id type ).sort, 
    1919      @first.attribute_names 
    2020    ) 
     
    2222   
    2323  def test_columns 
    24     assert_equal 11, Topic.columns.length 
     24    assert_equal 12, Topic.columns.length 
    2525  end 
    2626 
    2727  def test_content_columns 
    28     assert_equal 7, Topic.content_columns.length 
     28    assert_equal 8, Topic.content_columns.length 
    2929  end 
    3030