Commit e2abf597 authored by Kerri Miller's avatar Kerri Miller Committed by Kamil Trzciński

Add tests for #truncated?

While working on a separate issue, I noticed this public method didn't
have any unit test(s) associated with it, so I decided to fix that.
parent d3886e09
......@@ -165,7 +165,9 @@ module Gitlab
end
def truncated?
size && (size > loaded_size)
return false unless size && loaded_size
size > loaded_size
end
# Valid LFS object pointer is a text file consisting of
......
......@@ -613,6 +613,40 @@ describe Gitlab::Git::Blob, :seed_helper do
end
end
describe '#truncated?' do
context 'when blob.size is nil' do
let(:nil_size_blob) { Gitlab::Git::Blob.new(name: 'test', data: 'abcd') }
it 'returns false' do
expect(nil_size_blob.truncated?).to be_falsey
end
end
context 'when blob.data is missing' do
let(:nil_data_blob) { Gitlab::Git::Blob.new(name: 'test', size: 4) }
it 'returns false' do
expect(nil_data_blob.truncated?).to be_falsey
end
end
context 'when the blob is truncated' do
let(:truncated_blob) { Gitlab::Git::Blob.new(name: 'test', size: 40, data: 'abcd') }
it 'returns true' do
expect(truncated_blob.truncated?).to be_truthy
end
end
context 'when the blob is untruncated' do
let(:untruncated_blob) { Gitlab::Git::Blob.new(name: 'test', size: 4, data: 'abcd') }
it 'returns false' do
expect(untruncated_blob.truncated?).to be_falsey
end
end
end
describe 'metrics' do
it 'defines :gitlab_blob_truncated_true counter' do
expect(described_class).to respond_to(:gitlab_blob_truncated_true)
......
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