mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make active record encryption work with store attributes
Fix: https://github.com/rails/rails/issues/43012
This commit is contained in:
parent
6ec669b65d
commit
34ac8fc1f1
3 changed files with 12 additions and 0 deletions
|
@ -13,6 +13,7 @@ module ActiveRecord
|
|||
attr_reader :scheme, :cast_type
|
||||
|
||||
delegate :key_provider, :downcase?, :deterministic?, :previous_schemes, :with_context, :fixed?, to: :scheme
|
||||
delegate :accessor, to: :cast_type
|
||||
|
||||
# === Options
|
||||
#
|
||||
|
|
|
@ -47,6 +47,12 @@ class ActiveRecord::Encryption::EncryptableRecordTest < ActiveRecord::Encryption
|
|||
assert_encrypted_attribute(traffic_light, :state, states)
|
||||
end
|
||||
|
||||
test "encrypts store attributes with accessors" do
|
||||
traffic_light = EncryptedTrafficLightWithStoreState.create!(color: "red", long_state: %i[ green red ])
|
||||
assert_equal "red", traffic_light.color
|
||||
assert_encrypted_attribute(traffic_light, :state, { "color" => "red" })
|
||||
end
|
||||
|
||||
test "can configure a custom key provider on a per-record-class basis through the :key_provider option" do
|
||||
post = EncryptedPost.create!(title: "The Starfleet is here!", body: "take cover!")
|
||||
assert_encrypted_attribute(post, :body, "take cover!")
|
||||
|
|
|
@ -6,3 +6,8 @@ require "models/traffic_light"
|
|||
class EncryptedTrafficLight < TrafficLight
|
||||
encrypts :state
|
||||
end
|
||||
|
||||
class EncryptedTrafficLightWithStoreState < TrafficLight
|
||||
store :state, accessors: %i[ color ]
|
||||
encrypts :state
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue