aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/errors_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-05-30 14:00:14 -0400
committerSean Griffin <sean@seantheprogrammer.com>2016-05-30 14:04:29 -0400
commitb3dfd7d16cc37dcaf4298fe42e69a56ab3c6b00e (patch)
treea98a6e09e2067bb4a0505b2d744364f0adb04283 /activemodel/test/cases/errors_test.rb
parent88f763b047875483be10f554bc15278b28c86a8c (diff)
downloadrails-b3dfd7d16cc37dcaf4298fe42e69a56ab3c6b00e.tar.gz
rails-b3dfd7d16cc37dcaf4298fe42e69a56ab3c6b00e.tar.bz2
rails-b3dfd7d16cc37dcaf4298fe42e69a56ab3c6b00e.zip
Ensure that instances of `ActiveModel::Errors` can be marshalled
We now use default procs inside of the errors object, which gets included by default when marshaling anything that includes `ActiveModel::Validations`. This means that Active Record objects cannot be marshalled. We strip and apply the default proc ourselves. This will ensure the objects are YAML serializable as well, since YAML falls back to marshal implementations now. This is less important, however, as the errors aren't included when dumping Active Record objects. This commit does not include a changelog entry, as 5.0 is still in RC status at the time of writing, and 5.0.0 will not release with the bug this fixes. Fixes #25165
Diffstat (limited to 'activemodel/test/cases/errors_test.rb')
-rw-r--r--activemodel/test/cases/errors_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index fbf208836f..c90ee7021c 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -427,4 +427,13 @@ class ErrorsTest < ActiveModel::TestCase
assert_equal [:name], person.errors.messages.keys
assert_equal [:name], person.errors.details.keys
end
+
+ test "errors are marshalable" do
+ errors = ActiveModel::Errors.new(Person.new)
+ errors.add(:name, :invalid)
+ serialized = Marshal.load(Marshal.dump(errors))
+
+ assert_equal errors.messages, serialized.messages
+ assert_equal errors.details, serialized.details
+ end
end