summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/create_gpg_key_subkeys_from_gpg_keys_spec.rb
blob: 26d48cc820137e4656ef57cbda40712ef327e865 (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
require 'spec_helper'

describe Gitlab::BackgroundMigration::CreateGpgKeySubkeysFromGpgKeys, :migration, schema: 20171005130944 do
  context 'when GpgKey exists' do
    let!(:gpg_key) { create(:gpg_key, key: GpgHelpers::User3.public_key) }

    before do
      GpgKeySubkey.destroy_all
    end

    it 'generate the subkeys' do
      expect do
        described_class.new.perform(gpg_key.id)
      end.to change { gpg_key.subkeys.count }.from(0).to(2)
    end

    it 'schedules the signature update worker' do
      expect(InvalidGpgSignatureUpdateWorker).to receive(:perform_async).with(gpg_key.id)

      described_class.new.perform(gpg_key.id)
    end
  end

  context 'when GpgKey does not exist' do
    it 'does not do anything' do
      expect(Gitlab::Gpg).not_to receive(:subkeys_from_key)
      expect(InvalidGpgSignatureUpdateWorker).not_to receive(:perform_async)

      described_class.new.perform(123)
    end
  end
end