Browse files

Multiparameter attributes skip time zone conversion for time-only col…

…umns [#1030 state:resolved]
  • Loading branch information...
1 parent 980c298 commit 8bd62e31682b6fa3deb499c6a5338906fc559188 @gbuesing gbuesing committed Sep 14, 2008
Showing with 24 additions and 1 deletion.
  1. +5 −0 activerecord/CHANGELOG
  2. +1 −1 activerecord/lib/active_record/base.rb
  3. +18 −0 activerecord/test/cases/base_test.rb
View
5 activerecord/CHANGELOG
@@ -1,3 +1,8 @@
+*Edge*
+
+* Multiparameter attributes skip time zone conversion for time-only columns #1030 [Geoff Buesing]
+
+
*2.1.1 (September 4th, 2008)*
* Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp. #446. [Andrew Stone, Nik Wakelin]
View
2 activerecord/lib/active_record/base.rb
@@ -2632,7 +2632,7 @@ def assign_multiparameter_attributes(pairs)
end
def instantiate_time_object(name, values)
- if self.class.time_zone_aware_attributes && !self.class.skip_time_zone_conversion_for_attributes.include?(name.to_sym)
+ if self.class.send(:create_time_zone_conversion_attribute?, name, column_for_attribute(name))
Time.zone.local(*values)
else
Time.time_with_datetime_fallback(@@default_timezone, *values)
View
18 activerecord/test/cases/base_test.rb
@@ -1065,6 +1065,24 @@ def test_multiparameter_attributes_on_time_with_skip_time_zone_conversion_for_at
Time.zone = nil
Topic.skip_time_zone_conversion_for_attributes = []
end
+
+ def test_multiparameter_attributes_on_time_only_column_with_time_zone_aware_attributes_does_not_do_time_zone_conversion
+ ActiveRecord::Base.time_zone_aware_attributes = true
+ ActiveRecord::Base.default_timezone = :utc
+ Time.zone = ActiveSupport::TimeZone[-28800]
+ attributes = {
+ "bonus_time(1i)" => "2000", "bonus_time(2i)" => "1", "bonus_time(3i)" => "1",
+ "bonus_time(4i)" => "16", "bonus_time(5i)" => "24"
+ }
+ topic = Topic.find(1)
+ topic.attributes = attributes
+ assert_equal Time.utc(2000, 1, 1, 16, 24, 0), topic.bonus_time
+ assert topic.bonus_time.utc?
+ ensure
+ ActiveRecord::Base.time_zone_aware_attributes = false
+ ActiveRecord::Base.default_timezone = :local
+ Time.zone = nil
+ end
def test_multiparameter_attributes_on_time_with_empty_seconds
attributes = {

0 comments on commit 8bd62e3

Please sign in to comment.