summaryrefslogtreecommitdiff
path: root/spec/workers/create_commit_signature_worker_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 18:38:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-20 18:38:24 +0000
commit983a0bba5d2a042c4a3bbb22432ec192c7501d82 (patch)
treeb153cd387c14ba23bd5a07514c7c01fddf6a78a0 /spec/workers/create_commit_signature_worker_spec.rb
parenta2bddee2cdb38673df0e004d5b32d9f77797de64 (diff)
downloadgitlab-ce-983a0bba5d2a042c4a3bbb22432ec192c7501d82.tar.gz
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'spec/workers/create_commit_signature_worker_spec.rb')
-rw-r--r--spec/workers/create_commit_signature_worker_spec.rb59
1 files changed, 45 insertions, 14 deletions
diff --git a/spec/workers/create_commit_signature_worker_spec.rb b/spec/workers/create_commit_signature_worker_spec.rb
index d7235fcd907..f40482f2361 100644
--- a/spec/workers/create_commit_signature_worker_spec.rb
+++ b/spec/workers/create_commit_signature_worker_spec.rb
@@ -9,14 +9,14 @@ describe CreateCommitSignatureWorker do
let(:gpg_commit) { instance_double(Gitlab::Gpg::Commit) }
let(:x509_commit) { instance_double(Gitlab::X509::Commit) }
- context 'when a signature is found' do
- before do
- allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
- allow(project).to receive(:commits_by).with(oids: commit_shas).and_return(commits)
- end
+ before do
+ allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
+ allow(project).to receive(:commits_by).with(oids: commit_shas).and_return(commits)
+ end
- subject { described_class.new.perform(commit_shas, project.id) }
+ subject { described_class.new.perform(commit_shas, project.id) }
+ context 'when a signature is found' do
it 'calls Gitlab::Gpg::Commit#signature' do
commits.each do |commit|
allow(commit).to receive(:signature_type).and_return(:PGP)
@@ -67,9 +67,10 @@ describe CreateCommitSignatureWorker do
end
context 'handles when a string is passed in for the commit SHA' do
+ let(:commit_shas) { super().first }
+
before do
- allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
- allow(project).to receive(:commits_by).with(oids: Array(commit_shas.first)).and_return(commits)
+ allow(project).to receive(:commits_by).with(oids: [commit_shas]).and_return(commits)
allow(commits.first).to receive(:signature_type).and_return(:PGP)
end
@@ -78,35 +79,65 @@ describe CreateCommitSignatureWorker do
expect(gpg_commit).to receive(:signature).once
- described_class.new.perform(commit_shas.first, project.id)
+ subject
end
end
context 'when Commit is not found' do
let(:nonexisting_commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a34' }
+ let(:commit_shas) { [nonexisting_commit_sha] }
it 'does not raise errors' do
- expect { described_class.new.perform([nonexisting_commit_sha], project.id) }.not_to raise_error
+ expect { described_class.new.perform(commit_shas, project.id) }.not_to raise_error
end
end
context 'when Project is not found' do
- let(:nonexisting_project_id) { -1 }
+ let(:commits) { [] }
+ let(:project) { double(id: non_existing_record_id) }
it 'does not raise errors' do
- expect { described_class.new.perform(commit_shas, nonexisting_project_id) }.not_to raise_error
+ expect { subject }.not_to raise_error
end
it 'does not call Gitlab::Gpg::Commit#signature' do
expect_any_instance_of(Gitlab::Gpg::Commit).not_to receive(:signature)
- described_class.new.perform(commit_shas, nonexisting_project_id)
+ subject
end
it 'does not call Gitlab::X509::Commit#signature' do
expect_any_instance_of(Gitlab::X509::Commit).not_to receive(:signature)
- described_class.new.perform(commit_shas, nonexisting_project_id)
+ subject
+ end
+ end
+
+ context 'fetching signatures' do
+ before do
+ commits.each do |commit|
+ allow(commit).to receive(:signature_type).and_return(type)
+ end
+ end
+
+ context 'X509' do
+ let(:type) { :X509 }
+
+ it 'performs a single query for commit signatures' do
+ expect(X509CommitSignature).to receive(:by_commit_sha).with(commit_shas).once.and_return([])
+
+ subject
+ end
+ end
+
+ context 'PGP' do
+ let(:type) { :PGP }
+
+ it 'performs a single query for commit signatures' do
+ expect(GpgSignature).to receive(:by_commit_sha).with(commit_shas).once.and_return([])
+
+ subject
+ end
end
end
end