mirror of https://github.com/rails/rails
Merge pull request #46789 from ezekg/fix-string-keys-for-deterministic-active-record-encryption
Support string keys for queries on deterministic attributes
This commit is contained in:
commit
28386bdc0f
|
@ -44,12 +44,12 @@ module ActiveRecord
|
|||
return args if owner.deterministic_encrypted_attributes&.empty?
|
||||
|
||||
if args.is_a?(Array) && (options = args.first).is_a?(Hash)
|
||||
options = options.dup
|
||||
options = options.stringify_keys
|
||||
args[0] = options
|
||||
|
||||
owner.deterministic_encrypted_attributes&.each do |attribute_name|
|
||||
type = owner.type_for_attribute(attribute_name)
|
||||
if !type.previous_types.empty? && value = options[attribute_name]
|
||||
if !type.previous_types.empty? && value = options[attribute_name.to_s]
|
||||
options[attribute_name] = process_encrypted_query_argument(value, check_for_additional_values, type)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,6 +25,11 @@ class ActiveRecord::Encryption::ExtendedDeterministicQueriesTest < ActiveRecord:
|
|||
assert EncryptedBookWithDowncaseName.find_by(name: "DUNE")
|
||||
end
|
||||
|
||||
test "Works well with string attribute names" do
|
||||
UnencryptedBook.create! "name" => "Dune"
|
||||
assert EncryptedBook.find_by("name" => "Dune")
|
||||
end
|
||||
|
||||
test "find_or_create works" do
|
||||
EncryptedBook.find_or_create_by!(name: "Dune")
|
||||
assert EncryptedBook.find_by(name: "Dune")
|
||||
|
|
Loading…
Reference in New Issue