From 0951306ca5edbaec10edf3440d5ba11062a4f2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 8 Dec 2016 16:20:07 -0500 Subject: Make ActiveModel::Errors backward compatible with 4.2 If a Error object was serialized in the database as YAML in the Rails 4.2 version, if we load in the Rails 5.0 version it will miss the @details instance variable so methods like #clear and #add will start to fail. --- activemodel/lib/active_model/errors.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activemodel/lib/active_model/errors.rb') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 5ee9413cff..9df4ca51fe 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -419,16 +419,23 @@ module ActiveModel I18n.translate(key, options) end - def marshal_dump + def marshal_dump # :nodoc: [@base, without_default_proc(@messages), without_default_proc(@details)] end - def marshal_load(array) + def marshal_load(array) # :nodoc: @base, @messages, @details = array apply_default_array(@messages) apply_default_array(@details) end + def init_with(coder) # :nodoc: + coder.map.each { |k, v| instance_variable_set(:"@#{k}", v) } + @details ||= {} + apply_default_array(@messages) + apply_default_array(@details) + end + private def normalize_message(attribute, message, options) case message -- cgit v1.2.3