From 25989ab7ef1a444ed2abd5479f176d58e1d9462a Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 18 Oct 2019 11:11:44 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/lib/uploaded_file_spec.rb | 56 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'spec/lib/uploaded_file_spec.rb') diff --git a/spec/lib/uploaded_file_spec.rb b/spec/lib/uploaded_file_spec.rb index 2cb4727bd4b..2bbbd67b13c 100644 --- a/spec/lib/uploaded_file_spec.rb +++ b/spec/lib/uploaded_file_spec.rb @@ -72,16 +72,6 @@ describe UploadedFile do end end - context 'when only remote id is specified' do - let(:params) do - { 'file.remote_id' => 'remote_id' } - end - - it "raises an error" do - expect { subject }.to raise_error(UploadedFile::InvalidPathError, /file is invalid/) - end - end - context 'when verifying allowed paths' do let(:params) do { 'file.path' => temp_file.path } @@ -120,6 +110,52 @@ describe UploadedFile do end end + describe '.initialize' do + context 'when no size is provided' do + it 'determine size from local path' do + file = described_class.new(temp_file.path) + + expect(file.size).to eq(temp_file.size) + end + + it 'raises an exception if is a remote file' do + expect do + described_class.new(nil, remote_id: 'id') + end.to raise_error(UploadedFile::UnknownSizeError, 'Unable to determine file size') + end + end + + context 'when size is a number' do + let_it_be(:size) { 1.gigabyte } + + it 'is overridden by the size of the local file' do + file = described_class.new(temp_file.path, size: size) + + expect(file.size).to eq(temp_file.size) + end + + it 'is respected if is a remote file' do + file = described_class.new(nil, remote_id: 'id', size: size) + + expect(file.size).to eq(size) + end + end + + context 'when size is a string' do + it 'is converted to a number' do + file = described_class.new(nil, remote_id: 'id', size: '1') + + expect(file.size).to eq(1) + end + + it 'raises an exception if does not represent a number' do + expect do + described_class.new(nil, remote_id: 'id', size: 'not a number') + end.to raise_error(UploadedFile::UnknownSizeError, 'Unable to determine file size') + end + end + end + describe '#sanitize_filename' do it { expect(described_class.new(temp_file.path).sanitize_filename('spaced name')).to eq('spaced_name') } it { expect(described_class.new(temp_file.path).sanitize_filename('#$%^&')).to eq('_____') } -- cgit v1.2.3