lib/lockbox/model.rb in lockbox-0.4.4 vs lib/lockbox/model.rb in lockbox-0.4.5

- old
+ new

@@ -144,10 +144,14 @@ elsif !attributes_to_define_after_schema_loads.key?(name.to_s) # when migrating it's best to specify the type directly # however, we can try to use the original type if its already defined if attributes_to_define_after_schema_loads.key?(original_name.to_s) attribute name, attributes_to_define_after_schema_loads[original_name.to_s].first + elsif options[:migrating] + # we use the original attribute for serialization in the encrypt and decrypt methods + # so we can use a generic value here + attribute name, ActiveRecord::Type::Value.new else attribute name, :string end end @@ -317,11 +321,12 @@ message = [message].pack("G") unless message.nil? when :string, :binary # do nothing # encrypt will convert to binary else - type = (try(:attribute_types) || {})[name.to_s] + # use original name for serialized attributes + type = (try(:attribute_types) || {})[original_name.to_s] message = type.serialize(message) if type end end if message.nil? || (message == "" && !options[:padding]) @@ -359,10 +364,11 @@ message.force_encoding(Encoding::UTF_8) when :binary # do nothing # decrypt returns binary string else - type = (try(:attribute_types) || {})[name.to_s] + # use original name for serialized attributes + type = (try(:attribute_types) || {})[original_name.to_s] message = type.deserialize(message) if type message.force_encoding(Encoding::UTF_8) if !type || type.is_a?(ActiveModel::Type::String) end end