Skip to content

Commit 5b86259

Browse files
committed
Support string keys for queries on deterministic attributes
1 parent 52146de commit 5b86259

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

activerecord/lib/active_record/encryption/extended_deterministic_queries.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ def process_arguments(owner, args, check_for_additional_values)
4444
return args if owner.deterministic_encrypted_attributes&.empty?
4545

4646
if args.is_a?(Array) && (options = args.first).is_a?(Hash)
47-
options = options.dup
47+
options = options.stringify_keys
4848
args[0] = options
4949

5050
owner.deterministic_encrypted_attributes&.each do |attribute_name|
5151
type = owner.type_for_attribute(attribute_name)
52-
if !type.previous_types.empty? && value = options[attribute_name]
52+
if !type.previous_types.empty? && value = options[attribute_name.to_s]
5353
options[attribute_name] = process_encrypted_query_argument(value, check_for_additional_values, type)
5454
end
5555
end

activerecord/test/cases/encryption/extended_deterministic_queries_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class ActiveRecord::Encryption::ExtendedDeterministicQueriesTest < ActiveRecord:
2525
assert EncryptedBookWithDowncaseName.find_by(name: "DUNE")
2626
end
2727

28+
test "Works well with string attribute names" do
29+
UnencryptedBook.create! "name" => "Dune"
30+
assert EncryptedBook.find_by("name" => "Dune")
31+
end
32+
2833
test "find_or_create works" do
2934
EncryptedBook.find_or_create_by!(name: "Dune")
3035
assert EncryptedBook.find_by(name: "Dune")

0 commit comments

Comments
 (0)