From acffc062133e5793ac08b9529ab54689557766d4 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 12 May 2017 14:43:06 -0500 Subject: Specify explicitly whether a blob viewer should be loaded asynchronously --- spec/models/blob_viewer/base_spec.rb | 21 ++++----------------- spec/models/blob_viewer/server_side_spec.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 17 deletions(-) (limited to 'spec/models') diff --git a/spec/models/blob_viewer/base_spec.rb b/spec/models/blob_viewer/base_spec.rb index a6641970e1b..b3dc3252963 100644 --- a/spec/models/blob_viewer/base_spec.rb +++ b/spec/models/blob_viewer/base_spec.rb @@ -7,11 +7,12 @@ describe BlobViewer::Base, model: true do let(:viewer_class) do Class.new(described_class) do + include BlobViewer::ServerSide + self.extensions = %w(pdf) self.binary = true self.max_size = 1.megabyte self.absolute_max_size = 5.megabytes - self.client_side = false end end @@ -38,10 +39,10 @@ describe BlobViewer::Base, model: true do context 'when the file type is supported' do before do - viewer_class.file_type = :license + viewer_class.file_types = %i(license) viewer_class.binary = false end - + context 'when the binaryness matches' do let(:blob) { fake_blob(path: 'LICENSE', binary: false) } @@ -172,19 +173,5 @@ describe BlobViewer::Base, model: true do end end end - - context 'when the viewer is server side but the blob is stored externally' do - let(:project) { build(:empty_project, lfs_enabled: true) } - - let(:blob) { fake_blob(path: 'file.pdf', lfs: true) } - - before do - allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) - end - - it 'return :server_side_but_stored_externally' do - expect(viewer.render_error).to eq(:server_side_but_stored_externally) - end - end end end diff --git a/spec/models/blob_viewer/server_side_spec.rb b/spec/models/blob_viewer/server_side_spec.rb index ddca9b79390..f047953d540 100644 --- a/spec/models/blob_viewer/server_side_spec.rb +++ b/spec/models/blob_viewer/server_side_spec.rb @@ -22,4 +22,20 @@ describe BlobViewer::ServerSide, model: true do subject.prepare! end end + + describe '#render_error' do + context 'when the blob is stored externally' do + let(:project) { build(:empty_project, lfs_enabled: true) } + + let(:blob) { fake_blob(path: 'file.pdf', lfs: true) } + + before do + allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) + end + + it 'return :server_side_but_stored_externally' do + expect(subject.render_error).to eq(:server_side_but_stored_externally) + end + end + end end -- cgit v1.2.1 From b0a163208c1b428fc9f5adad6489f8a3ab884a2b Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 15 May 2017 10:03:34 -0500 Subject: Rename BlobViewer max_size to overridable_max_size and absolute_max_size to max_size --- spec/models/blob_viewer/base_spec.rb | 40 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'spec/models') diff --git a/spec/models/blob_viewer/base_spec.rb b/spec/models/blob_viewer/base_spec.rb index b3dc3252963..92fbf64a6b7 100644 --- a/spec/models/blob_viewer/base_spec.rb +++ b/spec/models/blob_viewer/base_spec.rb @@ -11,8 +11,8 @@ describe BlobViewer::Base, model: true do self.extensions = %w(pdf) self.binary = true - self.max_size = 1.megabyte - self.absolute_max_size = 5.megabytes + self.overridable_max_size = 1.megabyte + self.max_size = 5.megabytes end end @@ -69,45 +69,45 @@ describe BlobViewer::Base, model: true do end end - describe '#too_large?' do - context 'when the blob size is larger than the max size' do + describe '#exceeds_overridable_max_size?' do + context 'when the blob size is larger than the overridable max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } it 'returns true' do - expect(viewer.too_large?).to be_truthy + expect(viewer.exceeds_overridable_max_size?).to be_truthy end end - context 'when the blob size is smaller than the max size' do + context 'when the blob size is smaller than the overridable max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) } it 'returns false' do - expect(viewer.too_large?).to be_falsey + expect(viewer.exceeds_overridable_max_size?).to be_falsey end end end - describe '#absolutely_too_large?' do - context 'when the blob size is larger than the absolute max size' do + describe '#exceeds_max_size?' do + context 'when the blob size is larger than the max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) } it 'returns true' do - expect(viewer.absolutely_too_large?).to be_truthy + expect(viewer.exceeds_max_size?).to be_truthy end end - context 'when the blob size is smaller than the absolute max size' do + context 'when the blob size is smaller than the max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } it 'returns false' do - expect(viewer.absolutely_too_large?).to be_falsey + expect(viewer.exceeds_max_size?).to be_falsey end end end describe '#can_override_max_size?' do - context 'when the blob size is larger than the max size' do - context 'when the blob size is larger than the absolute max size' do + context 'when the blob size is larger than the overridable max size' do + context 'when the blob size is larger than the max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) } it 'returns false' do @@ -115,7 +115,7 @@ describe BlobViewer::Base, model: true do end end - context 'when the blob size is smaller than the absolute max size' do + context 'when the blob size is smaller than the max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } it 'returns true' do @@ -124,7 +124,7 @@ describe BlobViewer::Base, model: true do end end - context 'when the blob size is smaller than the max size' do + context 'when the blob size is smaller than the overridable max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) } it 'returns false' do @@ -139,7 +139,7 @@ describe BlobViewer::Base, model: true do viewer.override_max_size = true end - context 'when the blob size is larger than the absolute max size' do + context 'when the blob size is larger than the max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) } it 'returns :too_large' do @@ -147,7 +147,7 @@ describe BlobViewer::Base, model: true do end end - context 'when the blob size is smaller than the absolute max size' do + context 'when the blob size is smaller than the max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } it 'returns nil' do @@ -157,7 +157,7 @@ describe BlobViewer::Base, model: true do end context 'when the max size is not overridden' do - context 'when the blob size is larger than the max size' do + context 'when the blob size is larger than the overridable max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } it 'returns :too_large' do @@ -165,7 +165,7 @@ describe BlobViewer::Base, model: true do end end - context 'when the blob size is smaller than the max size' do + context 'when the blob size is smaller than the overridable max size' do let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) } it 'returns nil' do -- cgit v1.2.1