File tree Expand file tree Collapse file tree
spec/unit/lib/cloud_controller/errands Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -114,17 +114,21 @@ def encrypted_columns(model_klass)
114114 [ :encryption_key_label ] + model_klass . all_encrypted_fields . map ( &:values ) . flatten
115115 end
116116
117+ def nilable_columns ( entity )
118+ entity . values . except ( *encrypted_columns ( entity . class ) ) . select { |k , v | entity . db_schema [ k ] [ :type ] == :string && v . nil? } . keys
119+ end
120+
117121 shared_examples 'unencrypted fields' do
118122 it 'do not change their values' do
119123 entity = encrypted_models [ klass ]
120- string_columns_with_nil_value = entity . values . select { | _k , v | v . is_a? ( String ) && v . nil? } . keys
121- vals = entity . reload . values . except ( *encrypted_columns ( entity . class ) , *string_columns_with_nil_value )
124+ nilable_string_columns = nilable_columns ( entity )
125+ vals = entity . reload . values . except ( *encrypted_columns ( entity . class ) , *nilable_string_columns )
122126 expect ( vals . values . all? ( &:present? ) ) . to be_truthy , "all fields of #{ entity . class } need to have values"
123127
124128 RotateDatabaseKey . perform ( batch_size : 1 )
125129
126- expect ( entity . reload . values . except ( *encrypted_columns ( entity . class ) , *string_columns_with_nil_value ) ) . to eq ( vals )
127- expect ( entity . values . select { |k , _v | string_columns_with_nil_value . include? ( k ) } ) . to be_all ( &:nil? )
130+ expect ( entity . reload . values . except ( *encrypted_columns ( entity . class ) , *nilable_string_columns ) ) . to eq ( vals )
131+ expect ( entity . values . select { |k , _v | nilable_string_columns . include? ( k ) } . values ) . to be_all ( &:nil? )
128132 end
129133 end
130134
You can’t perform that action at this time.
0 commit comments