diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index f7aebc5ecb..c243bcc44d 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -136,7 +136,6 @@ module ActiveRecord end def deserialize(value) - return if value.nil? mapping.key(subtype.deserialize(value)) end diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index 27ec1a5a62..394ca511a4 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -236,6 +236,10 @@ class EnumTest < ActiveRecord::TestCase assert_nil @book.reload.status end + test "deserialize nil value to enum which defines nil value to hash" do + assert_equal "forgotten", books(:ddd).last_read + end + test "assign nil value" do @book.status = nil assert_nil @book.status