aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/CHANGELOG.md19
-rw-r--r--activemodel/lib/active_model/type/date.rb2
-rw-r--r--activemodel/test/cases/type/date_test.rb11
3 files changed, 30 insertions, 2 deletions
diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md
index 912b307683..55e0c85b00 100644
--- a/activemodel/CHANGELOG.md
+++ b/activemodel/CHANGELOG.md
@@ -1,4 +1,21 @@
-* Fix year value when casting a multiparameter time hash
+* Fix date value when casting a multiparameter date hash to not convert
+ from Gregorian date to Julian date.
+
+ Before:
+
+ Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
+ => #<Day id: nil, day: "0001-01-03", created_at: nil, updated_at: nil>
+
+ After:
+
+ Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
+ => #<Day id: nil, day: "0001-01-01", created_at: nil, updated_at: nil>
+
+ Fixes #28521.
+
+ *Sayan Chakraborty*
+
+* Fix year value when casting a multiparameter time hash.
When assigning a hash to a time attribute that's missing a year component
(e.g. a `time_select` with `:ignore_date` set to `true`) then the year
diff --git a/activemodel/lib/active_model/type/date.rb b/activemodel/lib/active_model/type/date.rb
index a7e6122ff4..c5fe926039 100644
--- a/activemodel/lib/active_model/type/date.rb
+++ b/activemodel/lib/active_model/type/date.rb
@@ -46,7 +46,7 @@ module ActiveModel
def value_from_multiparameter_assignment(*)
time = super
- time && time.to_date
+ time && new_date(time.year, time.mon, time.mday)
end
end
end
diff --git a/activemodel/test/cases/type/date_test.rb b/activemodel/test/cases/type/date_test.rb
index 9a393286b7..2dd1a55616 100644
--- a/activemodel/test/cases/type/date_test.rb
+++ b/activemodel/test/cases/type/date_test.rb
@@ -18,6 +18,17 @@ module ActiveModel
assert_equal date_string, type.cast(date_string).strftime("%F")
assert_equal date_string, type.cast(values_hash).strftime("%F")
end
+
+ def test_returns_correct_year
+ type = Type::Date.new
+
+ time = ::Time.utc(1, 1, 1)
+ date = ::Date.new(time.year, time.mon, time.mday)
+
+ values_hash_for_multiparameter_assignment = { 1 => 1, 2 => 1, 3 => 1 }
+
+ assert_equal date, type.cast(values_hash_for_multiparameter_assignment)
+ end
end
end
end