diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-04-26 15:48:49 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-04-27 12:23:27 -0500 |
commit | 87a3bd26fa1c6379801062fd65fea59e587baeee (patch) | |
tree | 0376d4fcf33aa230bff1f686710fc97e20363450 /spec/helpers/blob_helper_spec.rb | |
parent | c6b2a22f63bc7561beb3e596b14c62021d64c6e7 (diff) | |
download | gitlab-ce-87a3bd26fa1c6379801062fd65fea59e587baeee.tar.gz |
Address feedback
Diffstat (limited to 'spec/helpers/blob_helper_spec.rb')
-rw-r--r-- | spec/helpers/blob_helper_spec.rb | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index 8a89cd71e98..379f62f73e1 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -108,7 +108,11 @@ describe BlobHelper do context 'viewer related' do include FakeBlobHelpers - let(:project) { build(:empty_project) } + let(:project) { build(:empty_project, lfs_enabled: true) } + + before do + allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) + end let(:viewer_class) do Class.new(BlobViewer::Base) do @@ -122,24 +126,13 @@ describe BlobHelper do let(:viewer) { viewer_class.new(blob) } let(:blob) { fake_blob } - before do - assign(:project, project) - assign(:id, File.join('master', blob.path)) - - controller.params[:controller] = 'projects/blob' - controller.params[:action] = 'show' - controller.params[:namespace_id] = project.namespace.to_param - controller.params[:project_id] = project.to_param - controller.params[:id] = File.join('master', blob.path) - end - describe '#blob_render_error_reason' do context 'for error :too_large' do context 'when the blob size is larger than the absolute max size' do let(:blob) { fake_blob(size: 10.megabytes) } it 'returns an error message' do - expect(helper.blob_render_error_reason(viewer, :too_large)).to eq('it is larger than 5 MB') + expect(helper.blob_render_error_reason(viewer)).to eq('it is larger than 5 MB') end end @@ -147,25 +140,38 @@ describe BlobHelper do let(:blob) { fake_blob(size: 2.megabytes) } it 'returns an error message' do - expect(helper.blob_render_error_reason(viewer, :too_large)).to eq('it is larger than 1 MB') + expect(helper.blob_render_error_reason(viewer)).to eq('it is larger than 1 MB') end end end context 'for error :server_side_but_stored_in_lfs' do + let(:blob) { fake_blob(lfs: true) } + it 'returns an error message' do - expect(helper.blob_render_error_reason(viewer, :server_side_but_stored_in_lfs)).to eq('it is stored in LFS') + expect(helper.blob_render_error_reason(viewer)).to eq('it is stored in LFS') end end end describe '#blob_render_error_options' do + before do + assign(:project, project) + assign(:id, File.join('master', blob.path)) + + controller.params[:controller] = 'projects/blob' + controller.params[:action] = 'show' + controller.params[:namespace_id] = project.namespace.to_param + controller.params[:project_id] = project.to_param + controller.params[:id] = File.join('master', blob.path) + end + context 'for error :too_large' do context 'when the max size can be overridden' do let(:blob) { fake_blob(size: 2.megabytes) } it 'includes a "load it anyway" link' do - expect(helper.blob_render_error_options(viewer, :too_large)).to include(/load it anyway/) + expect(helper.blob_render_error_options(viewer)).to include(/load it anyway/) end end @@ -173,25 +179,25 @@ describe BlobHelper do let(:blob) { fake_blob(size: 10.megabytes) } it 'does not include a "load it anyway" link' do - expect(helper.blob_render_error_options(viewer, :too_large)).not_to include(/load it anyway/) + expect(helper.blob_render_error_options(viewer)).not_to include(/load it anyway/) end end end context 'when the viewer is rich' do context 'the blob is rendered as text' do - let(:blob) { fake_blob(path: 'file.md') } + let(:blob) { fake_blob(path: 'file.md', lfs: true) } it 'includes a "view the source" link' do - expect(helper.blob_render_error_options(viewer, :server_side_but_stored_in_lfs)).to include(/view the source/) + expect(helper.blob_render_error_options(viewer)).to include(/view the source/) end end context 'the blob is not rendered as text' do - let(:blob) { fake_blob(path: 'file.pdf', binary: true) } + let(:blob) { fake_blob(path: 'file.pdf', binary: true, lfs: true) } it 'does not include a "view the source" link' do - expect(helper.blob_render_error_options(viewer, :server_side_but_stored_in_lfs)).not_to include(/view the source/) + expect(helper.blob_render_error_options(viewer)).not_to include(/view the source/) end end end @@ -201,15 +207,15 @@ describe BlobHelper do viewer_class.type = :simple end - let(:blob) { fake_blob(path: 'file.md') } + let(:blob) { fake_blob(path: 'file.md', lfs: true) } it 'does not include a "view the source" link' do - expect(helper.blob_render_error_options(viewer, :server_side_but_stored_in_lfs)).not_to include(/view the source/) + expect(helper.blob_render_error_options(viewer)).not_to include(/view the source/) end end it 'includes a "download it" link' do - expect(helper.blob_render_error_options(viewer, :server_side_but_stored_in_lfs)).to include(/download it/) + expect(helper.blob_render_error_options(viewer)).to include(/download it/) end end end |