Skip to content

Commit 279337d

Browse files
authored
Merge pull request rails#43436 from Shopify/43306-serialize-anon-class
Raise error when serializing an anonymous class.
2 parents 430a851 + 0f259e7 commit 279337d

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

activejob/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Raise an `SerializationError` in `Serializer::ModuleSerializer`
2+
if the module name is not present.
3+
4+
*Veerpal Brar*
5+
6+
17
## Rails 7.0.0.alpha2 (September 15, 2021) ##
28

39
* No changes.

activejob/lib/active_job/serializers/module_serializer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module ActiveJob
44
module Serializers
55
class ModuleSerializer < ObjectSerializer # :nodoc:
66
def serialize(constant)
7+
raise SerializationError, "Serializing an anonymous class is not supported" unless constant.name
78
super("value" => constant.name)
89
end
910

activejob/test/cases/argument_serialization_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ClassArgument; end
5050
end
5151
end
5252

53-
[ Object.new, Person.find("5").to_gid ].each do |arg|
53+
[ Object.new, Person.find("5").to_gid, Class.new ].each do |arg|
5454
test "does not serialize #{arg.class}" do
5555
assert_raises ActiveJob::SerializationError do
5656
ActiveJob::Arguments.serialize [ arg ]

0 commit comments

Comments
 (0)