Restore HWIA support to AJ::Arguments.deserialize
Restore HashWithIndifferentAccess support to ActiveJob::Arguments.deserialize.
This commit is contained in:
parent
6b23b7e78c
commit
1f7bd2a171
|
@ -1,3 +1,7 @@
|
||||||
|
* Restore HashWithIndifferentAccess support to ActiveJob::Arguments.deserialize.
|
||||||
|
|
||||||
|
*Gannon McGibbon*
|
||||||
|
|
||||||
* Include deserialized arguments in job instances returned from
|
* Include deserialized arguments in job instances returned from
|
||||||
`assert_enqueued_with` and `assert_performed_with`
|
`assert_enqueued_with` and `assert_performed_with`
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,10 @@ module ActiveJob
|
||||||
end
|
end
|
||||||
|
|
||||||
def transform_symbol_keys(hash, symbol_keys)
|
def transform_symbol_keys(hash, symbol_keys)
|
||||||
hash.transform_keys do |key|
|
# NOTE: HashWithIndifferentAccess#transform_keys always
|
||||||
|
# returns stringified keys with indifferent access
|
||||||
|
# so we call #to_h here to ensure keys are symbolized.
|
||||||
|
hash.to_h.transform_keys do |key|
|
||||||
if symbol_keys.include?(key)
|
if symbol_keys.include?(key)
|
||||||
key.to_sym
|
key.to_sym
|
||||||
else
|
else
|
||||||
|
|
|
@ -73,6 +73,7 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
|
||||||
string_key = { "a" => 1, "_aj_symbol_keys" => [] }
|
string_key = { "a" => 1, "_aj_symbol_keys" => [] }
|
||||||
another_string_key = { "a" => 1 }
|
another_string_key = { "a" => 1 }
|
||||||
indifferent_access = { "a" => 1, "_aj_hash_with_indifferent_access" => true }
|
indifferent_access = { "a" => 1, "_aj_hash_with_indifferent_access" => true }
|
||||||
|
indifferent_access_symbol_key = symbol_key.with_indifferent_access
|
||||||
|
|
||||||
assert_equal(
|
assert_equal(
|
||||||
{ a: 1 },
|
{ a: 1 },
|
||||||
|
@ -90,6 +91,10 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
|
||||||
{ "a" => 1 },
|
{ "a" => 1 },
|
||||||
ActiveJob::Arguments.deserialize([indifferent_access]).first
|
ActiveJob::Arguments.deserialize([indifferent_access]).first
|
||||||
)
|
)
|
||||||
|
assert_equal(
|
||||||
|
{ a: 1 },
|
||||||
|
ActiveJob::Arguments.deserialize([indifferent_access_symbol_key]).first
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should maintain hash with indifferent access" do
|
test "should maintain hash with indifferent access" do
|
||||||
|
|
Loading…
Reference in New Issue