commit d97a95fc1895fe4c189c1eddc223b13934c648f3 Author: Nolan Eakins Date: Wed Apr 8 14:42:28 2009 -0400 Fixes #2457 by checking to see if only the hour and minute were passed to the writter and fills in the date if that's the case. diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 2a53851..7d2ac5b 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -3024,6 +3024,13 @@ module ActiveRecord #:nodoc: end def instantiate_time_object(name, values) + if values.length == 2 + # We only got the hour and minute, such as from + # ActionView::DateHelper#time_select so we'll add the missing + # info. + values = [ Date.today.year, Date.today.month, Date.today.day ] + values + end + if self.class.send(:create_time_zone_conversion_attribute?, name, column_for_attribute(name)) Time.zone.local(*values) else @@ -3053,12 +3060,13 @@ module ActiveRecord #:nodoc: send(name + "=", value) rescue => ex + raise ex errors << AttributeAssignmentError.new("error on assignment #{values.inspect} to #{name}", ex, name) end end end unless errors.empty? - raise MultiparameterAssignmentErrors.new(errors), "#{errors.size} error(s) on assignment of multiparameter attributes" + raise MultiparameterAssignmentErrors.new(errors), "#{errors.size} error(s) on assignment of multiparameter attributes: #{errors.collect(&:to_s).to_sentence}" end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 99d7796..8011af7 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1144,6 +1144,16 @@ class BasicsTest < ActiveRecord::TestCase assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on end + def test_multiparameter_attributes_on_time_with_empty_date + attributes = { + "written_on(1i)" => "", "written_on(2i)" => "", "written_on(3i)" => "", + "written_on(4i)" => "16", "written_on(5i)" => "24" + } + topic = Topic.find(1) + topic.attributes = attributes + assert_equal(Time.local(Date.today.year, Date.today.month, Date.today.day, 16, 24), topic.written_on) + end + def test_multiparameter_mass_assignment_protector task = Task.new time = Time.mktime(2000, 1, 1, 1)