summaryrefslogtreecommitdiff
path: root/spec/workers/create_gpg_signature_worker_spec.rb
diff options
context:
space:
mode:
authorAlexis Reigel <mail@koffeinfrei.org>2017-07-10 13:19:50 +0200
committerAlexis Reigel <mail@koffeinfrei.org>2017-07-27 15:43:37 +0200
commite63b693f28bf752f617bd0aa2f375db701d1600a (patch)
treee17bcb63ecadfae4b7e90fa6e48704d697d06c79 /spec/workers/create_gpg_signature_worker_spec.rb
parent4c5d4a69f0b5a813d2cb53e6f9af925cd3f9e8cb (diff)
downloadgitlab-ce-e63b693f28bf752f617bd0aa2f375db701d1600a.tar.gz
generate gpg signature on push
Diffstat (limited to 'spec/workers/create_gpg_signature_worker_spec.rb')
-rw-r--r--spec/workers/create_gpg_signature_worker_spec.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/workers/create_gpg_signature_worker_spec.rb b/spec/workers/create_gpg_signature_worker_spec.rb
new file mode 100644
index 00000000000..a23f0d6c34a
--- /dev/null
+++ b/spec/workers/create_gpg_signature_worker_spec.rb
@@ -0,0 +1,61 @@
+require 'spec_helper'
+
+describe CreateGpgSignatureWorker do
+ context 'when GpgKey is found' do
+ it 'calls Commit#signature' do
+ commit_sha = '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
+ project = create :project
+ commit = instance_double(Commit)
+
+ 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(commit).to receive(:signature)
+
+ described_class.new.perform(commit_sha, project.id)
+ end
+ end
+
+ context 'when Commit is not found' do
+ let(:nonexisting_commit_sha) { 'bogus' }
+ let(:project) { create :project }
+
+ it 'logs CreateGpgSignatureWorker process skipping' do
+ expect(Rails.logger).to receive(:error)
+ .with("CreateGpgSignatureWorker: couldn't find commit with commit_sha=bogus, skipping job")
+
+ described_class.new.perform(nonexisting_commit_sha, project.id)
+ end
+
+ it 'does not raise errors' do
+ expect { described_class.new.perform(nonexisting_commit_sha, project.id) }.not_to raise_error
+ end
+
+ it 'does not call Commit#signature' do
+ expect_any_instance_of(Commit).not_to receive(:signature)
+
+ described_class.new.perform(nonexisting_commit_sha, project.id)
+ end
+ end
+
+ context 'when Project is not found' do
+ let(:nonexisting_project_id) { -1 }
+
+ it 'logs CreateGpgSignatureWorker process skipping' do
+ expect(Rails.logger).to receive(:error)
+ .with("CreateGpgSignatureWorker: couldn't find project with ID=-1, skipping job")
+
+ described_class.new.perform(anything, nonexisting_project_id)
+ end
+
+ it 'does not raise errors' do
+ expect { described_class.new.perform(anything, nonexisting_project_id) }.not_to raise_error
+ end
+
+ it 'does not call Commit#signature' do
+ expect_any_instance_of(Commit).not_to receive(:signature)
+
+ described_class.new.perform(anything, nonexisting_project_id)
+ end
+ end
+end