Skip to content

Commit

Permalink
Fix error ActiveJob passed class with permitted?
Browse files Browse the repository at this point in the history
Resolves rails#48561
Co-authored-by: Sampat Badhe <sampatbadhe@gmail.com>
  • Loading branch information
abaldwin88 committed Jun 23, 2023
1 parent 5899ada commit 719e494
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activejob/lib/active_job/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def serialize_argument(argument)
result = serialize_hash(argument)
result[aj_hash_key] = symbol_keys
result
when -> (arg) { arg.respond_to?(:permitted?) }
when -> (arg) { arg.respond_to?(:permitted?) && arg.respond_to?(:to_h) }
serialize_indifferent_hash(argument.to_h)
else
if BigDecimal === argument && !ActiveJob.use_big_decimal_serializer
Expand Down
10 changes: 10 additions & 0 deletions activejob/test/cases/argument_serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class ClassArgument; end

class ClassArgument; end

class MyClassWithPermitted
def self.permitted?
end
end

setup do
@person = Person.find("5")
end
Expand Down Expand Up @@ -112,6 +117,11 @@ class ClassArgument; end
)
end

# Regression test to #48561
test "serialize a class with permitted? defined" do
assert_arguments_unchanged MyClassWithPermitted
end

test "serialize a hash" do
symbol_key = { a: 1 }
string_key = { "a" => 1 }
Expand Down

0 comments on commit 719e494

Please sign in to comment.