9
9
class SerializedAttributeTest < ActiveRecord ::TestCase
10
10
def setup
11
11
ActiveRecord . use_yaml_unsafe_load = true
12
+ @yaml_column_permitted_classes_default = ActiveRecord . yaml_column_permitted_classes
13
+ end
14
+
15
+ def teardown
16
+ Topic . serialize ( "content" )
17
+ ActiveRecord . yaml_column_permitted_classes = @yaml_column_permitted_classes_default
12
18
end
13
19
14
20
fixtures :topics , :posts
@@ -23,8 +29,8 @@ class ImportantTopic < Topic
23
29
serialize :important , type : Hash
24
30
end
25
31
26
- teardown do
27
- Topic . serialize ( "content" )
32
+ class ClassifiedTopic < Topic
33
+ serialize :important , type : Class
28
34
end
29
35
30
36
def test_serialize_does_not_eagerly_load_columns
@@ -166,6 +172,14 @@ def test_serialized_string_attribute
166
172
assert_equal ( myobj , topic . content )
167
173
end
168
174
175
+ def test_serialized_class_attribute
176
+ ActiveRecord . yaml_column_permitted_classes += [ Class ]
177
+
178
+ topic = ClassifiedTopic . create ( important : Symbol ) . reload
179
+ assert_equal ( Symbol , topic . important )
180
+ assert_not_empty ClassifiedTopic . where ( important : Symbol )
181
+ end
182
+
169
183
def test_nil_serialized_attribute_without_class_constraint
170
184
topic = Topic . new
171
185
assert_nil topic . content
@@ -551,9 +565,17 @@ def test_serialized_attribute_works_under_concurrent_initial_access
551
565
552
566
class SerializedAttributeTestWithYamlSafeLoad < SerializedAttributeTest
553
567
def setup
568
+ @use_yaml_unsafe_load = ActiveRecord . use_yaml_unsafe_load
569
+ @yaml_column_permitted_classes_default = ActiveRecord . yaml_column_permitted_classes
554
570
ActiveRecord . use_yaml_unsafe_load = false
555
571
end
556
572
573
+ def teardown
574
+ Topic . serialize ( "content" )
575
+ ActiveRecord . yaml_column_permitted_classes = @yaml_column_permitted_classes_default
576
+ ActiveRecord . use_yaml_unsafe_load = @use_yaml_unsafe_load
577
+ end
578
+
557
579
def test_serialized_attribute
558
580
Topic . serialize ( "content" , type : String )
559
581
0 commit comments