aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2016-12-08 16:20:07 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2016-12-08 16:27:47 -0500
commit0951306ca5edbaec10edf3440d5ba11062a4f2e5 (patch)
tree6b5be8f1351de82d4edc68184325c496c6ed54d2 /activemodel/lib
parentdeaaf805243e7fe3cda06f5ec8558ea0e9d9eeef (diff)
downloadrails-0951306ca5edbaec10edf3440d5ba11062a4f2e5.tar.gz
rails-0951306ca5edbaec10edf3440d5ba11062a4f2e5.tar.bz2
rails-0951306ca5edbaec10edf3440d5ba11062a4f2e5.zip
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.
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/errors.rb11
1 files changed, 9 insertions, 2 deletions
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