Skip to content

Commit 82b3093

Browse files
committed
Tests for encryption/decryption backed by a binary field
1 parent 5cf6d57 commit 82b3093

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

spec/crypt_keeper/model_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
end
5555
end
5656

57+
5758
context "Encryption and Decryption" do
5859
let(:plain_text) { 'plain_text' }
5960
let(:cipher_text) { 'tooltxet_nialp' }
@@ -104,6 +105,21 @@
104105
expect_any_instance_of(CryptKeeper::Provider::Encryptor).to_not receive(:decrypt)
105106
subject.find(record.id).storage
106107
end
108+
109+
context "with a binary database field" do
110+
subject { create_encrypted_model :storage_binary, passphrase: 'tool', encryptor: :encryptor }
111+
112+
it "encrypts the data" do
113+
expect_any_instance_of(CryptKeeper::Provider::Encryptor).to receive(:encrypt).with('testing')
114+
subject.create!(storage_binary: 'testing')
115+
end
116+
117+
it "decrypts the data" do
118+
record = subject.create!(storage_binary: 'testing')
119+
expect_any_instance_of(CryptKeeper::Provider::Encryptor).to receive(:decrypt).at_least(1).times.with('toolgnitset')
120+
subject.find(record.id).storage_binary
121+
end
122+
end
107123
end
108124

109125
context "Search" do

0 commit comments

Comments
 (0)