aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2018-01-23 14:08:46 -0700
committerSean Griffin <sean@seantheprogrammer.com>2018-01-23 14:12:13 -0700
commit0af36c62a5710e023402e37b019ad9982e69de4b (patch)
tree178cbe93ac6e6e2c489ac21a124c354e1300f20d /activemodel/test
parent6003dafc1f844275d6a7fe9e626eaeb1176c8e8a (diff)
downloadrails-0af36c62a5710e023402e37b019ad9982e69de4b.tar.gz
rails-0af36c62a5710e023402e37b019ad9982e69de4b.tar.bz2
rails-0af36c62a5710e023402e37b019ad9982e69de4b.zip
Allow attributes with a proc default to be marshalled
We don't implement much custom marshalling logic for these objects, but the proc default case needs to be handled separately. Unfortunately there's no way to just say "do what you would have done but with this value for one ivar", so we have to manually implement `marshal_load` as well. The test case is a little bit funky, but I'd really like an equality test in there, and there's no easy way to add one now that this is out of AR (since the `attributes` method isn't here) Fixes #31216
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/attributes_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activemodel/test/cases/attributes_test.rb b/activemodel/test/cases/attributes_test.rb
index e43bf15335..7c1d813ce0 100644
--- a/activemodel/test/cases/attributes_test.rb
+++ b/activemodel/test/cases/attributes_test.rb
@@ -64,5 +64,14 @@ module ActiveModel
assert_equal "4.4", data.integer_field
end
+
+ test "attributes with proc defaults can be marshalled" do
+ data = ModelForAttributesTest.new
+ attributes = data.instance_variable_get(:@attributes)
+ round_tripped = Marshal.load(Marshal.dump(data))
+ new_attributes = round_tripped.instance_variable_get(:@attributes)
+
+ assert_equal attributes, new_attributes
+ end
end
end