apply proper fix for timezone support, and fix specs accordingly

This commit is contained in:
Brian Lopez 2010-06-08 15:16:37 -07:00
parent 5d8346cf38
commit d4beaf3059
2 changed files with 7 additions and 6 deletions

View File

@ -57,8 +57,8 @@ module ActiveRecord
when :integer then value.to_i rescue value ? 1 : 0 when :integer then value.to_i rescue value ? 1 : 0
when :float then value.to_f # returns self if it's already a Float when :float then value.to_f # returns self if it's already a Float
when :decimal then self.class.value_to_decimal(value) when :decimal then self.class.value_to_decimal(value)
when :datetime, :timestamp then value.class == Time ? value.in_time_zone : self.class.string_to_time(value) when :datetime, :timestamp then value.class == Time ? value : self.class.string_to_time(value)
when :time then value.class == Time ? value.in_time_zone : self.class.string_to_dummy_time(value) when :time then value.class == Time ? value : self.class.string_to_dummy_time(value)
when :date then value.class == Date ? value : self.class.string_to_date(value) when :date then value.class == Date ? value : self.class.string_to_date(value)
when :binary then value when :binary then value
when :boolean then self.class.value_to_boolean(value) when :boolean then self.class.value_to_boolean(value)
@ -73,8 +73,8 @@ module ActiveRecord
when :integer then "#{var_name}.to_i rescue #{var_name} ? 1 : 0" when :integer then "#{var_name}.to_i rescue #{var_name} ? 1 : 0"
when :float then "#{var_name}.to_f" when :float then "#{var_name}.to_f"
when :decimal then "#{self.class.name}.value_to_decimal(#{var_name})" when :decimal then "#{self.class.name}.value_to_decimal(#{var_name})"
when :datetime, :timestamp then "#{var_name}.class == Time ? #{var_name}.in_time_zone : #{self.class.name}.string_to_time(#{var_name})" when :datetime, :timestamp then "#{var_name}.class == Time ? #{var_name} : #{self.class.name}.string_to_time(#{var_name})"
when :time then "#{var_name}.class == Time ? #{var_name}.in_time_zone : #{self.class.name}.string_to_dummy_time(#{var_name})" when :time then "#{var_name}.class == Time ? #{var_name} : #{self.class.name}.string_to_dummy_time(#{var_name})"
when :date then "#{var_name}.class == Date ? #{var_name} : #{self.class.name}.string_to_date(#{var_name})" when :date then "#{var_name}.class == Date ? #{var_name} : #{self.class.name}.string_to_date(#{var_name})"
when :binary then nil when :binary then nil
when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})" when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})"

View File

@ -28,6 +28,7 @@ describe ActiveRecord::ConnectionAdapters::Mysql2Adapter do
context "columns" do context "columns" do
before(:all) do before(:all) do
ActiveRecord::Base.default_timezone = 'Pacific Time (US & Canada)' ActiveRecord::Base.default_timezone = 'Pacific Time (US & Canada)'
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :database => 'test') ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :database => 'test')
Mysql2Test2.connection.execute %[ Mysql2Test2.connection.execute %[
CREATE TABLE IF NOT EXISTS mysql2_test2 ( CREATE TABLE IF NOT EXISTS mysql2_test2 (
@ -123,9 +124,9 @@ describe ActiveRecord::ConnectionAdapters::Mysql2Adapter do
test.double_test.should eql('1.0000'.to_f) test.double_test.should eql('1.0000'.to_f)
test.decimal_test.should eql(BigDecimal.new('1.0000')) test.decimal_test.should eql(BigDecimal.new('1.0000'))
test.date_test.should eql(Date.parse('2010-01-01')) test.date_test.should eql(Date.parse('2010-01-01'))
test.date_time_test.should eql(DateTime.parse('2010-01-01 00:00:00')) test.date_time_test.should eql(Time.utc(2010,1,1,0,0,0))
test.timestamp_test.class.should eql(ActiveSupport::TimeWithZone) test.timestamp_test.class.should eql(ActiveSupport::TimeWithZone)
test.time_test.class.should eql(ActiveSupport::TimeWithZone) test.time_test.class.should eql(Time)
test.year_test.should eql(2010) test.year_test.should eql(2010)
test.char_test.should eql('abcdefghij') test.char_test.should eql('abcdefghij')
test.varchar_test.should eql('abcdefghij') test.varchar_test.should eql('abcdefghij')