When assigning an integer to an attr_encrypted attribute the following error is raised:
TypeError: can't convert Fixnum into String
This is because the integer value is passed straight through to Encryptor which passes it to the OpenSSL::Cipher::Cipher instance. The error only occurs when marshaling is not used; I assume the marshaling procedure always outputs a string acceptable to the cipher.
As a solution I suggest type casting the assigned value. This can be achieved by updating line 192 of attr_encrypted.rb from...
value = options[:marshaler].send(options[:dump_method], value) if options[:marshal]
value = options[:marshal] ? options[:marshaler].send(options[:dump_method], value) : value.to_s
value = options[:marshaler].send(options[:dump_method], value)
value = value.to_s
...depending on whether you prefer clarity or brevity.
I think it's reasonable to assume the user intends all assigned values to be cast to string when marshaling is not used, which is why I propose doing it here in the AttrEncrypted module.
type cast values as strings before encrypting, closed by d325268
Thanks for the clear and thorough writeup! attr-encrypted/attr_encrypted@d325268
type cast values as strings before encrypting, closes #16