diff options
author | Toon Claes <toon@gitlab.com> | 2018-10-30 11:56:47 +0100 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2018-11-07 11:29:31 +0100 |
commit | 149b63272202d78566af59db192c668a8803c910 (patch) | |
tree | ab3435679615c963cf2836131037b21e868d114d /spec/models/upload_spec.rb | |
parent | 1c481b7aacdc7e90d0f349dc8e848adaf0813c65 (diff) | |
download | gitlab-ce-149b63272202d78566af59db192c668a8803c910.tar.gz |
Backport changes from EE
Now the files are identical again compared to EE.
These are backported from
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/5050
Diffstat (limited to 'spec/models/upload_spec.rb')
-rw-r--r-- | spec/models/upload_spec.rb | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index e3544b84b50..5a0df9fbbb0 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -112,10 +112,51 @@ describe Upload do expect(upload).to exist end - it 'returns false when the file does not exist' do - upload = described_class.new(path: "#{__FILE__}-nope", store: ObjectStorage::Store::LOCAL) + context 'when the file does not exist' do + it 'returns false' do + upload = described_class.new(path: "#{__FILE__}-nope", store: ObjectStorage::Store::LOCAL) - expect(upload).not_to exist + expect(upload).not_to exist + end + + context 'when the record is persisted' do + it 'sends a message to Sentry' do + upload = create(:upload, :issuable_upload) + + expect(Gitlab::Sentry).to receive(:enabled?).and_return(true) + expect(Raven).to receive(:capture_message).with("Upload file does not exist", extra: upload.attributes) + + upload.exist? + end + + it 'increments a metric counter to signal a problem' do + upload = create(:upload, :issuable_upload) + + counter = double(:counter) + expect(counter).to receive(:increment) + expect(Gitlab::Metrics).to receive(:counter).with(:upload_file_does_not_exist_total, 'The number of times an upload record could not find its file').and_return(counter) + + upload.exist? + end + end + + context 'when the record is not persisted' do + it 'does not send a message to Sentry' do + upload = described_class.new(path: "#{__FILE__}-nope", store: ObjectStorage::Store::LOCAL) + + expect(Raven).not_to receive(:capture_message) + + upload.exist? + end + + it 'does not increment a metric counter' do + upload = described_class.new(path: "#{__FILE__}-nope", store: ObjectStorage::Store::LOCAL) + + expect(Gitlab::Metrics).not_to receive(:counter) + + upload.exist? + end + end end end |