Skip to content

Commit eaa74ee

Browse files
authored
EncryptedAttributeType#type should return cast_type's type. (rails#52247)
1 parent 7186ceb commit eaa74ee

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

activerecord/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
2+
actual cast type.
3+
4+
*Vasiliy Ermolovich*
5+
16
* SQLite3Adapter: Bulk insert fixtures.
27

38
Previously one insert command was executed for each fixture, now they are

activerecord/lib/active_record/encryption/encrypted_attribute_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ module Encryption
77
# This is the central piece that connects the encryption system with +encrypts+ declarations in the
88
# model classes. Whenever you declare an attribute as encrypted, it configures an +EncryptedAttributeType+
99
# for that attribute.
10-
class EncryptedAttributeType < ::ActiveRecord::Type::Text
10+
class EncryptedAttributeType < ::ActiveModel::Type::Value
1111
include ActiveModel::Type::Helpers::Mutable
1212

1313
attr_reader :scheme, :cast_type
1414

1515
delegate :key_provider, :downcase?, :deterministic?, :previous_schemes, :with_context, :fixed?, to: :scheme
16-
delegate :accessor, to: :cast_type
16+
delegate :accessor, :type, to: :cast_type
1717

1818
# === Options
1919
#

activerecord/test/cases/encryption/encryptable_record_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ def name
418418
assert EncryptedBookWithCustomCompressor.create!(name: name).name.start_with?("[compressed]")
419419
end
420420

421+
test "type method returns cast type" do
422+
assert_equal :string, EncryptedBook.type_for_attribute(:name).type
423+
assert_equal :text, EncryptedPost.type_for_attribute(:body).type
424+
end
425+
421426
private
422427
def build_derived_key_provider_with(hash_digest_class)
423428
ActiveRecord::Encryption.with_encryption_context(key_generator: ActiveRecord::Encryption::KeyGenerator.new(hash_digest_class: hash_digest_class)) do

0 commit comments

Comments
 (0)