diff options
author | Toon Claes <toon@gitlab.com> | 2019-02-28 19:57:34 +0100 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2019-02-28 19:57:34 +0100 |
commit | 62d7990b9bb30cf33ed87017c5c633d1cccc75c2 (patch) | |
tree | c3e1b69c58a412ba1c6f50a0337a23d9f9d6e1a4 /spec/models/upload_spec.rb | |
parent | f6453eca992a9c142268e78ac782cef98110d183 (diff) | |
download | gitlab-ce-tc-standard-gem.tar.gz |
Ran standardrb --fix on the whole codebasetc-standard-gem
Inspired by https://twitter.com/searls/status/1101137953743613952 I
decided to try https://github.com/testdouble/standard on our codebase.
It's opinionated, but at least it's a _standard_.
Diffstat (limited to 'spec/models/upload_spec.rb')
-rw-r--r-- | spec/models/upload_spec.rb | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 5a0df9fbbb0..3098f71c5d7 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -1,27 +1,27 @@ -require 'rails_helper' +require "rails_helper" describe Upload do - describe 'assocations' do + describe "assocations" do it { is_expected.to belong_to(:model) } end - describe 'validations' do + describe "validations" do it { is_expected.to validate_presence_of(:size) } it { is_expected.to validate_presence_of(:path) } it { is_expected.to validate_presence_of(:model) } it { is_expected.to validate_presence_of(:uploader) } end - describe 'callbacks' do - context 'for a file above the checksum threshold' do - it 'schedules checksum calculation' do - stub_const('UploadChecksumWorker', spy) + describe "callbacks" do + context "for a file above the checksum threshold" do + it "schedules checksum calculation" do + stub_const("UploadChecksumWorker", spy) upload = described_class.create( path: __FILE__, size: described_class::CHECKSUM_THRESHOLD + 1.kilobyte, model: build_stubbed(:user), - uploader: double('ExampleUploader'), + uploader: double("ExampleUploader"), store: ObjectStorage::Store::LOCAL ) @@ -30,13 +30,13 @@ describe Upload do end end - context 'for a file at or below the checksum threshold' do - it 'calculates checksum immediately before save' do + context "for a file at or below the checksum threshold" do + it "calculates checksum immediately before save" do upload = described_class.new( path: __FILE__, size: described_class::CHECKSUM_THRESHOLD, model: build_stubbed(:user), - uploader: double('ExampleUploader'), + uploader: double("ExampleUploader"), store: ObjectStorage::Store::LOCAL ) @@ -46,11 +46,11 @@ describe Upload do end end - describe 'after_destroy' do - context 'uploader is FileUploader-based' do + describe "after_destroy" do + context "uploader is FileUploader-based" do subject { create(:upload, :issuable_upload) } - it 'calls delete_file!' do + it "calls delete_file!" do is_expected.to receive(:delete_file!) subject.destroy @@ -59,9 +59,9 @@ describe Upload do end end - describe '#absolute_path' do - it 'returns the path directly when already absolute' do - path = '/path/to/namespace/project/secret/file.jpg' + describe "#absolute_path" do + it "returns the path directly when already absolute" do + path = "/path/to/namespace/project/secret/file.jpg" upload = described_class.new(path: path, store: ObjectStorage::Store::LOCAL) expect(upload).not_to receive(:uploader_class) @@ -70,8 +70,8 @@ describe Upload do end it "delegates to the uploader's absolute_path method" do - uploader = spy('FakeUploader') - upload = described_class.new(path: 'secret/file.jpg', store: ObjectStorage::Store::LOCAL) + uploader = spy("FakeUploader") + upload = described_class.new(path: "secret/file.jpg", store: ObjectStorage::Store::LOCAL) expect(upload).to receive(:uploader_class).and_return(uploader) upload.absolute_path @@ -80,21 +80,21 @@ describe Upload do end end - describe '#calculate_checksum!' do + describe "#calculate_checksum!" do let(:upload) do described_class.new(path: __FILE__, size: described_class::CHECKSUM_THRESHOLD - 1.megabyte, store: ObjectStorage::Store::LOCAL) end - it 'sets `checksum` to SHA256 sum of the file' do + it "sets `checksum` to SHA256 sum of the file" do expected = Digest::SHA256.file(__FILE__).hexdigest expect { upload.calculate_checksum! } .to change { upload.checksum }.from(nil).to(expected) end - it 'sets `checksum` to nil for a non-existent file' do + it "sets `checksum` to nil for a non-existent file" do expect(upload).to receive(:exist?).and_return(false) checksum = Digest::SHA256.file(__FILE__).hexdigest @@ -105,22 +105,22 @@ describe Upload do end end - describe '#exist?' do - it 'returns true when the file exists' do + describe "#exist?" do + it "returns true when the file exists" do upload = described_class.new(path: __FILE__, store: ObjectStorage::Store::LOCAL) expect(upload).to exist end - context 'when the file does not exist' do - it 'returns false' do + 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 end - context 'when the record is persisted' do - it 'sends a message to Sentry' do + 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) @@ -129,19 +129,19 @@ describe Upload do upload.exist? end - it 'increments a metric counter to signal a problem' do + 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) + 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 + 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) @@ -149,7 +149,7 @@ describe Upload do upload.exist? end - it 'does not increment a metric counter' do + 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) @@ -161,8 +161,8 @@ describe Upload do end describe "#uploader_context" do - subject { create(:upload, :issuable_upload, secret: 'secret', filename: 'file.txt') } + subject { create(:upload, :issuable_upload, secret: "secret", filename: "file.txt") } - it { expect(subject.uploader_context).to match(a_hash_including(secret: 'secret', identifier: 'file.txt')) } + it { expect(subject.uploader_context).to match(a_hash_including(secret: "secret", identifier: "file.txt")) } end end |