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

Changeset 8547

Show
Ignore:
Timestamp:
01/03/08 21:33:40 (4 months ago)
Author:
rick
Message:

fix tz_attributes on unchanged timestamps

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/tztime/lib/tz_time_helpers/active_record_methods.rb

    r6523 r8547  
    2424          def fix_timezone 
    2525            tz_time_attributes.each do |attribute| 
    26               time  = read_attribute(attribute) 
    27               fixed = (time.acts_like?(:time) || time.acts_like?(:date)) ? TzTime.at(time) : nil 
    28               write_attribute(attribute, fixed) 
     26              time = read_attribute(attribute) 
     27              if (time.acts_like?(:time) || time.acts_like?(:date)) && !time.utc? 
     28                write_attribute(attribute, Time.at(TzTime.zone.local_to_utc(time))) 
     29              end 
    2930            end 
    3031          end 
  • plugins/tztime/test/active_record_methods_test.rb

    r6521 r8547  
    22require 'rubygems' 
    33require 'test/unit' 
     4begin 
     5  require 'ruby-debug' 
     6  Debugger.start 
     7rescue LoadError 
     8  # no debugger for you 
     9end 
    410 
    511class MockRecord 
    612  attr_writer :due_on 
    713  def self.before_validation(*args) nil end 
     14   
     15  def [](attribute) 
     16    read_attribute(attribute) 
     17  end 
    818   
    919  protected 
     
    2939    def test_should_access_utc_time_as_local_with_getter_method 
    3040      @record.due_on = Time.utc(2006, 1, 1) 
    31       assert_equal @record.due_on, TzTime.local(2005, 12, 31, 18) 
     41      assert_equal TzTime.local(2005, 12, 31, 18), @record.due_on 
    3242    end 
    3343     
    34     def test_should_fix_timezones 
     44    def test_should_fix_local_timezones 
     45      @record.due_on = Time.utc(2006, 1, 1) 
     46      assert_equal TzTime.local(2005, 12, 31, 18), @record.due_on 
     47      @record.send :fix_timezone 
     48      assert_equal Time.utc(2006, 1, 1), @record[:due_on] 
     49    end 
     50     
     51    def test_should_not_fix_utc_timezones 
    3552      @record.due_on = Time.utc(2006, 1, 1) 
    3653      @record.send :fix_timezone 
    37       assert_equal @record.due_on, TzTime.local(2006, 1, 1) 
     54      assert_equal Time.utc(2006, 1, 1), @record[:due_on] 
    3855    end 
    3956  end