Merge pull request #39998 from kamipo/fix_enum_deserialize_mapping_nil

Fix deserializing enum mapping nil
This commit is contained in:
Ryuta Kamizono 2020-08-07 14:03:32 +09:00 committed by GitHub
commit 0133428ffa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

@ -136,7 +136,6 @@ def cast(value)
end
def deserialize(value)
return if value.nil?
mapping.key(subtype.deserialize(value))
end

@ -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