Skip to content

Commit 2fd61a9

Browse files
committed
Add a test for querying serialized attributes containing Module
Extracted from rails#47352
1 parent e54ef0a commit 2fd61a9

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

activerecord/test/cases/serialized_attribute_test.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
class SerializedAttributeTest < ActiveRecord::TestCase
1010
def setup
1111
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
1218
end
1319

1420
fixtures :topics, :posts
@@ -23,8 +29,8 @@ class ImportantTopic < Topic
2329
serialize :important, type: Hash
2430
end
2531

26-
teardown do
27-
Topic.serialize("content")
32+
class ClassifiedTopic < Topic
33+
serialize :important, type: Class
2834
end
2935

3036
def test_serialize_does_not_eagerly_load_columns
@@ -166,6 +172,14 @@ def test_serialized_string_attribute
166172
assert_equal(myobj, topic.content)
167173
end
168174

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+
169183
def test_nil_serialized_attribute_without_class_constraint
170184
topic = Topic.new
171185
assert_nil topic.content
@@ -551,9 +565,17 @@ def test_serialized_attribute_works_under_concurrent_initial_access
551565

552566
class SerializedAttributeTestWithYamlSafeLoad < SerializedAttributeTest
553567
def setup
568+
@use_yaml_unsafe_load = ActiveRecord.use_yaml_unsafe_load
569+
@yaml_column_permitted_classes_default = ActiveRecord.yaml_column_permitted_classes
554570
ActiveRecord.use_yaml_unsafe_load = false
555571
end
556572

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+
557579
def test_serialized_attribute
558580
Topic.serialize("content", type: String)
559581

0 commit comments

Comments
 (0)