2017-07-10 11:19:50 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe CreateGpgSignatureWorker do
|
2017-08-15 11:22:55 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
2017-07-10 11:19:50 +00:00
|
|
|
context 'when GpgKey is found' do
|
2017-08-15 11:22:55 +00:00
|
|
|
let(:commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' }
|
2017-07-10 11:19:50 +00:00
|
|
|
|
2017-08-15 11:22:55 +00:00
|
|
|
it 'calls Gitlab::Gpg::Commit#signature' do
|
2017-08-24 12:21:26 +00:00
|
|
|
commit = instance_double(Commit)
|
|
|
|
gpg_commit = instance_double(Gitlab::Gpg::Commit)
|
2017-07-10 11:19:50 +00:00
|
|
|
|
2017-08-24 12:21:26 +00:00
|
|
|
allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
|
|
|
|
allow(project).to receive(:commit).with(commit_sha).and_return(commit)
|
|
|
|
|
|
|
|
expect(Gitlab::Gpg::Commit).to receive(:new).with(commit).and_return(gpg_commit)
|
|
|
|
expect(gpg_commit).to receive(:signature)
|
2017-07-10 11:19:50 +00:00
|
|
|
|
|
|
|
described_class.new.perform(commit_sha, project.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Commit is not found' do
|
2017-08-15 11:22:55 +00:00
|
|
|
let(:nonexisting_commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a34' }
|
2017-07-10 11:19:50 +00:00
|
|
|
|
|
|
|
it 'does not raise errors' do
|
|
|
|
expect { described_class.new.perform(nonexisting_commit_sha, project.id) }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Project is not found' do
|
|
|
|
let(:nonexisting_project_id) { -1 }
|
|
|
|
|
|
|
|
it 'does not raise errors' do
|
|
|
|
expect { described_class.new.perform(anything, nonexisting_project_id) }.not_to raise_error
|
|
|
|
end
|
|
|
|
|
2017-08-15 11:22:55 +00:00
|
|
|
it 'does not call Gitlab::Gpg::Commit#signature' do
|
|
|
|
expect_any_instance_of(Gitlab::Gpg::Commit).not_to receive(:signature)
|
2017-07-10 11:19:50 +00:00
|
|
|
|
|
|
|
described_class.new.perform(anything, nonexisting_project_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|