twinslash/enumerize — pull request #28 by jimryan (2012-03-24 02:59:54+00:00)
Title: Don't cast nil to string

This changes the enumerized attribute writer method to store ``nil`` if the value being written isn't in the attribute's values list. Previously, it was being cast to a string, so an empty string was being stored in these cases. To make matters more confusing, the reader method doesn't cast the return value from ``Attribute#find_value``, so it'd appear nil, but that's not what was being stored.

In addition, I don't cast the value being passed to the writer method if it is ``nil`` when storing it in the ``_enumerized_values_for_validation`` hash. This allows you to explicitly set an enumerized attribute to ``nil``, whereas before it'd be converted to an empty string. Since the inclusion validator ignores nils, this means that explicitly setting an enumerized attribute to ``nil`` will pass that validation. This can be solved with a presence validator, or possibly accepting an ``:allow_nil`` option in the ``enumerize`` options hash that's passed right to the inclusion validator.