Skip to content

Commit

Permalink
EncryptedAttributeType#type should return cast_type's type. (rails#52247
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nashby authored Aug 13, 2024
1 parent 7186ceb commit eaa74ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Fix `ActiveRecord::Encryption::EncryptedAttributeType#type` to return
actual cast type.

*Vasiliy Ermolovich*

* SQLite3Adapter: Bulk insert fixtures.

Previously one insert command was executed for each fixture, now they are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ module Encryption
# This is the central piece that connects the encryption system with +encrypts+ declarations in the
# model classes. Whenever you declare an attribute as encrypted, it configures an +EncryptedAttributeType+
# for that attribute.
class EncryptedAttributeType < ::ActiveRecord::Type::Text
class EncryptedAttributeType < ::ActiveModel::Type::Value
include ActiveModel::Type::Helpers::Mutable

attr_reader :scheme, :cast_type

delegate :key_provider, :downcase?, :deterministic?, :previous_schemes, :with_context, :fixed?, to: :scheme
delegate :accessor, to: :cast_type
delegate :accessor, :type, to: :cast_type

# === Options
#
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/encryption/encryptable_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ def name
assert EncryptedBookWithCustomCompressor.create!(name: name).name.start_with?("[compressed]")
end

test "type method returns cast type" do
assert_equal :string, EncryptedBook.type_for_attribute(:name).type
assert_equal :text, EncryptedPost.type_for_attribute(:body).type
end

private
def build_derived_key_provider_with(hash_digest_class)
ActiveRecord::Encryption.with_encryption_context(key_generator: ActiveRecord::Encryption::KeyGenerator.new(hash_digest_class: hash_digest_class)) do
Expand Down

0 comments on commit eaa74ee

Please sign in to comment.