blob: bf4094eaa4994be2ab05ce22360b98351cfdadfe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe EncryptStaticObjectsExternalStorageAuthToken, :migration do
let(:application_settings) do
Class.new(ActiveRecord::Base) do
self.table_name = 'application_settings'
end
end
context 'when static_objects_external_storage_auth_token is not set' do
it 'does nothing' do
application_settings.create!
reversible_migration do |migration|
migration.before -> {
settings = application_settings.first
expect(settings.static_objects_external_storage_auth_token).to be_nil
expect(settings.static_objects_external_storage_auth_token_encrypted).to be_nil
}
migration.after -> {
settings = application_settings.first
expect(settings.static_objects_external_storage_auth_token).to be_nil
expect(settings.static_objects_external_storage_auth_token_encrypted).to be_nil
}
end
end
end
context 'when static_objects_external_storage_auth_token is set' do
it 'encrypts static_objects_external_storage_auth_token' do
settings = application_settings.create!
settings.update_column(:static_objects_external_storage_auth_token, 'Test')
reversible_migration do |migration|
migration.before -> {
settings = application_settings.first
expect(settings.static_objects_external_storage_auth_token).to eq('Test')
expect(settings.static_objects_external_storage_auth_token_encrypted).to be_nil
}
migration.after -> {
settings = application_settings.first
expect(settings.static_objects_external_storage_auth_token).to eq('Test')
expect(settings.static_objects_external_storage_auth_token_encrypted).to be_present
}
end
end
end
context 'when static_objects_external_storage_auth_token is empty string' do
it 'does not break' do
settings = application_settings.create!
settings.update_column(:static_objects_external_storage_auth_token, '')
reversible_migration do |migration|
migration.before -> {
settings = application_settings.first
expect(settings.static_objects_external_storage_auth_token).to eq('')
expect(settings.static_objects_external_storage_auth_token_encrypted).to be_nil
}
migration.after -> {
settings = application_settings.first
expect(settings.static_objects_external_storage_auth_token).to eq('')
expect(settings.static_objects_external_storage_auth_token_encrypted).to be_nil
}
end
end
end
end
|