mirror of https://github.com/rails/rails
Merge pull request #48462 from iamradioactive/remove_additional_query
Do not revalidate encrypted attribute with current encrypted_type
This commit is contained in:
commit
99e2999f96
|
@ -14,7 +14,7 @@ module ActiveRecord
|
|||
klass = record.class
|
||||
if klass.deterministic_encrypted_attributes&.include?(attribute)
|
||||
encrypted_type = klass.type_for_attribute(attribute)
|
||||
[ encrypted_type, *encrypted_type.previous_types ].each do |type|
|
||||
encrypted_type.previous_types.each do |type|
|
||||
encrypted_value = type.serialize(value)
|
||||
ActiveRecord::Encryption.without_encryption do
|
||||
super(record, attribute, encrypted_value)
|
||||
|
|
|
@ -55,4 +55,11 @@ class ActiveRecord::Encryption::UniquenessValidationsTest < ActiveRecord::Encryp
|
|||
OldEncryptionBook.create! name: "DUNE"
|
||||
end
|
||||
end
|
||||
|
||||
test "uniqueness validation does not revalidate the attribute with current encryption type" do
|
||||
EncryptedBookWithUniquenessValidation.create!(name: "dune")
|
||||
record = EncryptedBookWithUniquenessValidation.create(name: "dune")
|
||||
|
||||
assert_equal record.errors.count, 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,13 @@ class EncryptedBook < ActiveRecord::Base
|
|||
encrypts :name, deterministic: true
|
||||
end
|
||||
|
||||
class EncryptedBookWithUniquenessValidation < ActiveRecord::Base
|
||||
self.table_name = "encrypted_books"
|
||||
|
||||
validates :name, uniqueness: true
|
||||
encrypts :name, deterministic: true
|
||||
end
|
||||
|
||||
class EncryptedBookWithDowncaseName < ActiveRecord::Base
|
||||
self.table_name = "encrypted_books"
|
||||
|
||||
|
|
Loading…
Reference in New Issue