diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-03-19 11:50:36 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-03-19 11:51:18 -0600 |
commit | 1e6afa40209ca15aee811bb5797c175c0d8eaad4 (patch) | |
tree | b608e2243ab30a3d61465464c04bf06a359a760b | |
parent | 4857be1638bd1713375d82bf23a96c11dc6ecfe8 (diff) | |
download | rails-1e6afa40209ca15aee811bb5797c175c0d8eaad4.tar.gz rails-1e6afa40209ca15aee811bb5797c175c0d8eaad4.tar.bz2 rails-1e6afa40209ca15aee811bb5797c175c0d8eaad4.zip |
Don't cast nil to string in pg enums
Fixes #19389.
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/enum.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/enum_test.rb | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/enum.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/enum.rb index b3b610a5f6..91d339f32c 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/enum.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/enum.rb @@ -7,7 +7,9 @@ module ActiveRecord :enum end - def cast(value) + private + + def cast_value(value) value.to_s end end diff --git a/activerecord/test/cases/adapters/postgresql/enum_test.rb b/activerecord/test/cases/adapters/postgresql/enum_test.rb index 7458de23d8..ed084483bc 100644 --- a/activerecord/test/cases/adapters/postgresql/enum_test.rb +++ b/activerecord/test/cases/adapters/postgresql/enum_test.rb @@ -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 |