1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't cast nil to string in pg enums

Fixes #19389.
This commit is contained in:
Sean Griffin 2015-03-19 11:50:36 -06:00
parent 4857be1638
commit 1e6afa4020
2 changed files with 11 additions and 1 deletions

View file

@ -7,7 +7,9 @@ module ActiveRecord
:enum
end
def cast(value)
private
def cast_value(value)
value.to_s
end
end

View file

@ -80,4 +80,12 @@ class PostgresqlEnumTest < ActiveRecord::TestCase
assert_equal "happy", enum.current_mood
end
def test_assigning_enum_to_nil
model = PostgresqlEnum.new(current_mood: nil)
assert_nil model.current_mood
assert model.save
assert_nil model.reload.current_mood
end
end