Commit ce869e39 authored by Douwe Maan's avatar Douwe Maan

Fix Diff#too_large? and specs

parent d9461314
...@@ -230,9 +230,11 @@ module Gitlab ...@@ -230,9 +230,11 @@ module Gitlab
end end
def too_large? def too_large?
return @too_large if defined?(@too_large) if @too_large.nil?
@too_large = @diff.bytesize >= SIZE_LIMIT
@too_large = @diff.bytesize >= SIZE_LIMIT else
@too_large
end
end end
def too_large! def too_large!
......
...@@ -168,21 +168,19 @@ describe BlobHelper do ...@@ -168,21 +168,19 @@ describe BlobHelper do
controller.params[:id] = File.join('master', blob.path) controller.params[:id] = File.join('master', blob.path)
end end
context 'for error :too_large' do context 'for error :collapsed' do
context 'when the size limit can be overridden' do let(:blob) { fake_blob(size: 2.megabytes) }
let(:blob) { fake_blob(size: 2.megabytes) }
it 'includes a "load it anyway" link' do it 'includes a "load it anyway" link' do
expect(helper.blob_render_error_options(viewer)).to include(/load it anyway/) expect(helper.blob_render_error_options(viewer)).to include(/load it anyway/)
end
end end
end
context 'when the size limit cannot be overridden' do context 'for error :too_large' do
let(:blob) { fake_blob(size: 10.megabytes) } let(:blob) { fake_blob(size: 10.megabytes) }
it 'does not include a "load it anyway" link' do it 'does not include a "load it anyway" link' do
expect(helper.blob_render_error_options(viewer)).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 'when the viewer is rich' do
......
...@@ -85,12 +85,12 @@ EOT ...@@ -85,12 +85,12 @@ EOT
# The patch total size is 200, with lines between 21 and 54. # The patch total size is 200, with lines between 21 and 54.
# This is a quick-and-dirty way to test this. Ideally, a new patch is # This is a quick-and-dirty way to test this. Ideally, a new patch is
# added to the test repo with a size that falls between the real limits. # added to the test repo with a size that falls between the real limits.
stub_const("#{described_class}::MAX_SIZE", 150) stub_const("#{described_class}::SIZE_LIMIT", 150)
stub_const("#{described_class}::OVERRIDABLE_MAX_SIZE", 100) stub_const("#{described_class}::COLLAPSE_LIMIT", 100)
end end
it 'prunes the diff as a large diff instead of as a collapsed diff' do it 'prunes the diff as a large diff instead of as a collapsed diff' do
diff = described_class.new(@rugged_diff, collapse: true) diff = described_class.new(@rugged_diff, expanded: false)
expect(diff.diff).to be_empty expect(diff.diff).to be_empty
expect(diff).to be_too_large expect(diff).to be_too_large
...@@ -299,15 +299,15 @@ EOT ...@@ -299,15 +299,15 @@ EOT
describe '#collapsed?' do describe '#collapsed?' do
it 'returns true for a diff that is quite large' do it 'returns true for a diff that is quite large' do
diff = described_class.new(diff: 'a' * 20480) diff = described_class.new({ diff: 'a' * 20480 }, expanded: false)
expect(diff).to be_collapsible expect(diff).to be_collapsed
end end
it 'returns false for a diff that is small enough' do it 'returns false for a diff that is small enough' do
diff = described_class.new(diff: 'a') diff = described_class.new({ diff: 'a' }, expanded: false)
expect(diff).not_to be_collapsible expect(diff).not_to be_collapsed
end end
end end
......
...@@ -105,36 +105,8 @@ describe BlobViewer::Base, model: true do ...@@ -105,36 +105,8 @@ describe BlobViewer::Base, model: true do
end end
end end
describe '#can_expanded?' do
context 'when the blob size is larger than the collapse limit' do
context 'when the blob size is larger than the size limit' do
let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) }
it 'returns false' do
expect(viewer.can_expanded?).to be_falsey
end
end
context 'when the blob size is smaller than the size limit' do
let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
it 'returns true' do
expect(viewer.can_expanded?).to be_truthy
end
end
end
context 'when the blob size is smaller than the collapse limit' do
let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) }
it 'returns false' do
expect(viewer.can_expanded?).to be_falsey
end
end
end
describe '#render_error' do describe '#render_error' do
context 'when the size limit is overridden' do context 'when expanded' do
before do before do
viewer.expanded = true viewer.expanded = true
end end
...@@ -156,12 +128,12 @@ describe BlobViewer::Base, model: true do ...@@ -156,12 +128,12 @@ describe BlobViewer::Base, model: true do
end end
end end
context 'when the size limit is not overridden' do context 'when not expanded' do
context 'when the blob size is larger than the collapse limit' do context 'when the blob size is larger than the collapse limit' do
let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
it 'returns :too_large' do it 'returns :collapsed' do
expect(viewer.render_error).to eq(:too_large) expect(viewer.render_error).to eq(:collapsed)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment