mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix deserializing enum mapping nil
Follow up to #38086. User assigned nil is type casted by #38086, but loaded nil from database does not yet, this fixes that.
This commit is contained in:
parent
e8cf45dc4a
commit
afeb756828
2 changed files with 4 additions and 1 deletions
|
@ -136,7 +136,6 @@ module ActiveRecord
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue