From eb73dfc0677cb5b3a0f559020fe5d7df556056b4 Mon Sep 17 00:00:00 2001
From: Sayan Chakraborty <mail.sayanc@gmail.com>
Date: Sat, 1 Jul 2017 19:18:18 +0530
Subject: Return correct date in ActiveModel for time to date conversions
 time.to_date conversion happens considering leap years so a conversion of
 "Day.new({'day(1i)'=>'1', 'day(2i)'=>'1', 'day(3i)'=>'1'})" results in saving
 the date as Mon, 03 Jan 0001 which might seem weird on the user level, hence
 falling back to parsing on string level resolves this data mismatch Fixes
 #28521

---
 activemodel/test/cases/type/date_test.rb | 11 +++++++++++
 1 file changed, 11 insertions(+)

(limited to 'activemodel/test')

diff --git a/activemodel/test/cases/type/date_test.rb b/activemodel/test/cases/type/date_test.rb
index e8cf178612..c50a549d3d 100644
--- a/activemodel/test/cases/type/date_test.rb
+++ b/activemodel/test/cases/type/date_test.rb
@@ -15,6 +15,17 @@ module ActiveModel
         date_string = ::Time.now.utc.strftime("%F")
         assert_equal date_string, type.cast(date_string).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
-- 
cgit v1.2.3