diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-12-08 16:20:07 -0500 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-12-08 16:27:47 -0500 |
commit | 0951306ca5edbaec10edf3440d5ba11062a4f2e5 (patch) | |
tree | 6b5be8f1351de82d4edc68184325c496c6ed54d2 /activemodel/test | |
parent | deaaf805243e7fe3cda06f5ec8558ea0e9d9eeef (diff) | |
download | rails-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/test')
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index fc840bf192..e868d20fc8 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -365,4 +365,24 @@ class ErrorsTest < ActiveModel::TestCase assert_equal errors.messages, serialized.messages assert_equal errors.details, serialized.details end + + test "errors are backward compatible with the Rails 4.2 format" do + yaml = <<-CODE.strip_heredoc + --- !ruby/object:ActiveModel::Errors + base: &1 !ruby/object:ErrorsTest::Person + errors: !ruby/object:ActiveModel::Errors + base: *1 + messages: {} + messages: {} + CODE + + errors = YAML.load(yaml) + errors.add(:name, :invalid) + assert_equal({ name: ["is invalid"] }, errors.messages) + assert_equal({ name: [{ error: :invalid }] }, errors.details) + + errors.clear + assert_equal({}, errors.messages) + assert_equal({}, errors.details) + end end |