aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activejob/CHANGELOG.md4
-rw-r--r--activejob/lib/active_job/arguments.rb5
-rw-r--r--activejob/test/cases/argument_serialization_test.rb5
-rw-r--r--activerecord/lib/active_record/locking/pessimistic.rb6
4 files changed, 16 insertions, 4 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md
index 768e6bd250..8bbecd5a5a 100644
--- a/activejob/CHANGELOG.md
+++ b/activejob/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Restore HashWithIndifferentAccess support to ActiveJob::Arguments.deserialize.
+
+ *Gannon McGibbon*
+
* Include deserialized arguments in job instances returned from
`assert_enqueued_with` and `assert_performed_with`
diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb
index 8dcf588f35..31347194d2 100644
--- a/activejob/lib/active_job/arguments.rb
+++ b/activejob/lib/active_job/arguments.rb
@@ -147,7 +147,10 @@ module ActiveJob
end
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)
key.to_sym
else
diff --git a/activejob/test/cases/argument_serialization_test.rb b/activejob/test/cases/argument_serialization_test.rb
index f07529d743..8b2981926f 100644
--- a/activejob/test/cases/argument_serialization_test.rb
+++ b/activejob/test/cases/argument_serialization_test.rb
@@ -73,6 +73,7 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
string_key = { "a" => 1, "_aj_symbol_keys" => [] }
another_string_key = { "a" => 1 }
indifferent_access = { "a" => 1, "_aj_hash_with_indifferent_access" => true }
+ indifferent_access_symbol_key = symbol_key.with_indifferent_access
assert_equal(
{ a: 1 },
@@ -90,6 +91,10 @@ class ArgumentSerializationTest < ActiveSupport::TestCase
{ "a" => 1 },
ActiveJob::Arguments.deserialize([indifferent_access]).first
)
+ assert_equal(
+ { a: 1 },
+ ActiveJob::Arguments.deserialize([indifferent_access_symbol_key]).first
+ )
end
test "should maintain hash with indifferent access" do
diff --git a/activerecord/lib/active_record/locking/pessimistic.rb b/activerecord/lib/active_record/locking/pessimistic.rb
index 5d1d15c94d..130ef8a330 100644
--- a/activerecord/lib/active_record/locking/pessimistic.rb
+++ b/activerecord/lib/active_record/locking/pessimistic.rb
@@ -14,9 +14,9 @@ module ActiveRecord
# of your own such as 'LOCK IN SHARE MODE' or 'FOR UPDATE NOWAIT'. Example:
#
# Account.transaction do
- # # select * from accounts where name = 'shugo' limit 1 for update
- # shugo = Account.where("name = 'shugo'").lock(true).first
- # yuko = Account.where("name = 'yuko'").lock(true).first
+ # # select * from accounts where name = 'shugo' limit 1 for update nowait
+ # shugo = Account.lock("FOR UPDATE NOWAIT").find_by(name: "shugo")
+ # yuko = Account.lock("FOR UPDATE NOWAIT").find_by(name: "yuko")
# shugo.balance -= 100
# shugo.save!
# yuko.balance += 100