summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-10-07 19:16:18 +0000
committerStan Hu <stanhu@gmail.com>2017-10-07 19:16:18 +0000
commit01d7335b43256867ab8cc05c0e14844c9faeb916 (patch)
tree331da0dbc62a970fc4b87a7e4efe5480eb288c62 /spec
parent3e96288aa4715658c055894513fb640d3637b933 (diff)
parent4aa2deb4782f1f3b516bfaecdb57203765bbb123 (diff)
downloadgitlab-ce-01d7335b43256867ab8cc05c0e14844c9faeb916.tar.gz
Merge branch '38890-fix-gpg-signature-updater-when-commit-is-missing' into 'master'
Fix error with GPG signature updater when commit was deleted Closes #38890 See merge request gitlab-org/gitlab-ce!14749
Diffstat (limited to 'spec')
-rw-r--r--spec/models/gpg_signature_spec.rb28
1 files changed, 22 insertions, 6 deletions
diff --git a/spec/models/gpg_signature_spec.rb b/spec/models/gpg_signature_spec.rb
index db033016c37..0136bb61c07 100644
--- a/spec/models/gpg_signature_spec.rb
+++ b/spec/models/gpg_signature_spec.rb
@@ -1,6 +1,10 @@
require 'rails_helper'
RSpec.describe GpgSignature do
+ let(:commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' }
+ let!(:project) { create(:project, :repository, path: 'sample-project') }
+ let!(:commit) { create(:commit, project: project, sha: commit_sha) }
+ let(:gpg_signature) { create(:gpg_signature, commit_sha: commit_sha) }
let(:gpg_key) { create(:gpg_key) }
let(:gpg_key_subkey) { create(:gpg_key_subkey) }
@@ -19,11 +23,6 @@ RSpec.describe GpgSignature do
describe '#commit' do
it 'fetches the commit through the project' do
- commit_sha = '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
- project = create :project, :repository
- commit = create :commit, project: project
- gpg_signature = create :gpg_signature, commit_sha: commit_sha
-
expect_any_instance_of(Project).to receive(:commit).with(commit_sha).and_return(commit)
gpg_signature.commit
@@ -44,11 +43,28 @@ RSpec.describe GpgSignature do
end
it 'clears gpg_key and gpg_key_subkey_id when passing nil' do
- gpg_signature = create(:gpg_signature, gpg_key: gpg_key_subkey)
gpg_signature.update_attribute(:gpg_key, nil)
expect(gpg_signature.gpg_key_id).to be_nil
expect(gpg_signature.gpg_key_subkey_id).to be_nil
end
end
+
+ describe '#gpg_commit' do
+ context 'when commit does not exist' do
+ it 'returns nil' do
+ allow(gpg_signature).to receive(:commit).and_return(nil)
+
+ expect(gpg_signature.gpg_commit).to be_nil
+ end
+ end
+
+ context 'when commit exists' do
+ it 'returns an instance of Gitlab::Gpg::Commit' do
+ allow(gpg_signature).to receive(:commit).and_return(commit)
+
+ expect(gpg_signature.gpg_commit).to be_an_instance_of(Gitlab::Gpg::Commit)
+ end
+ end
+ end
end