diff options
author | alpaca-tc <alpaca-tc@alpaca.tc> | 2016-07-15 04:12:11 +0900 |
---|---|---|
committer | alpaca-tc <alpaca-tc@alpaca.tc> | 2016-07-19 22:35:45 +0900 |
commit | 780535017ae3071c87f29b1bf7ea2015959a6c21 (patch) | |
tree | ab3a54bbc1a1e250c63e1e3585c7d5ca0512e26c /activerecord | |
parent | d8bc0964d29837407efe425d7a65ab9a27d96e82 (diff) | |
download | rails-780535017ae3071c87f29b1bf7ea2015959a6c21.tar.gz rails-780535017ae3071c87f29b1bf7ea2015959a6c21.tar.bz2 rails-780535017ae3071c87f29b1bf7ea2015959a6c21.zip |
Fixes multiparameter attributes conversion with time_zone_aware_attributes and invalid params
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/multiparameter_attributes_test.rb | 14 |
3 files changed, 19 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 1d0e4b32a3..ba9f07e26e 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fixes multi-parameter attributes conversion with invalid params. + + *Hiroyuki Ishii* + * Add newline between each migration in `structure.sql`. Keeps schema migration inserts as a single commit, but allows for easier diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb index e160460286..cbb4f0cff8 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -39,7 +39,7 @@ module ActiveRecord end def set_time_zone_without_conversion(value) - ::Time.zone.local_to_utc(value).in_time_zone + ::Time.zone.local_to_utc(value).in_time_zone if value end def map_avoiding_infinite_recursion(value) diff --git a/activerecord/test/cases/multiparameter_attributes_test.rb b/activerecord/test/cases/multiparameter_attributes_test.rb index d05cb22740..59c340ceb7 100644 --- a/activerecord/test/cases/multiparameter_attributes_test.rb +++ b/activerecord/test/cases/multiparameter_attributes_test.rb @@ -202,6 +202,20 @@ class MultiParameterAttributeTest < ActiveRecord::TestCase Topic.reset_column_information end + def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_and_invalid_time_params + with_timezone_config aware_attributes: true do + Topic.reset_column_information + attributes = { + "written_on(1i)" => "2004", "written_on(2i)" => "", "written_on(3i)" => "" + } + topic = Topic.find(1) + topic.attributes = attributes + assert_nil topic.written_on + end + ensure + Topic.reset_column_information + end + def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_false with_timezone_config default: :local, aware_attributes: false, zone: -28800 do attributes = { |