add tests for UploadIO#from_io
This commit is contained in:
parent
8daeb2cc1e
commit
0cc3a1f814
|
@ -22,30 +22,50 @@ require 'hurley/test'
|
||||||
# TODO: Upload from file
|
# TODO: Upload from file
|
||||||
|
|
||||||
RSpec.describe Google::Apis::Core::UploadIO do
|
RSpec.describe Google::Apis::Core::UploadIO do
|
||||||
let(:upload_io) { Google::Apis::Core::UploadIO.from_file(file) }
|
context 'from_file' do
|
||||||
|
let(:upload_io) { Google::Apis::Core::UploadIO.from_file(file) }
|
||||||
|
|
||||||
context 'with text file' do
|
context 'with text file' do
|
||||||
let(:file) { File.join(FIXTURES_DIR, 'files', 'test.txt') }
|
let(:file) { File.join(FIXTURES_DIR, 'files', 'test.txt') }
|
||||||
it 'should infer content type from file' do
|
it 'should infer content type from file' do
|
||||||
expect(upload_io.content_type).to eql('text/plain')
|
expect(upload_io.content_type).to eql('text/plain')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should allow overriding the mime type' do
|
||||||
|
io = Google::Apis::Core::UploadIO.from_file(file, content_type: 'application/json')
|
||||||
|
expect(io.content_type).to eql('application/json')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should allow overriding the mime type' do
|
context 'with unknown type' do
|
||||||
io = Google::Apis::Core::UploadIO.from_file(file, content_type: 'application/json')
|
let(:file) { File.join(FIXTURES_DIR, 'files', 'test.blah') }
|
||||||
expect(io.content_type).to eql('application/json')
|
it 'should use the default mime type' do
|
||||||
|
expect(upload_io.content_type).to eql('application/octet-stream')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should allow overriding the mime type' do
|
||||||
|
io = Google::Apis::Core::UploadIO.from_file(file, content_type: 'application/json')
|
||||||
|
expect(io.content_type).to eql('application/json')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with unknown type' do
|
context 'from_io' do
|
||||||
let(:file) { File.join(FIXTURES_DIR, 'files', 'test.blah') }
|
|
||||||
it 'should use the default mime type' do
|
context 'with i/o stream' do
|
||||||
expect(upload_io.content_type).to eql('application/octet-stream')
|
let(:io) { StringIO.new 'Hello google' }
|
||||||
|
|
||||||
|
it 'should setup default content-type' do
|
||||||
|
upload_io = Google::Apis::Core::UploadIO.from_io(io)
|
||||||
|
expect(upload_io.content_type).to eql Google::Apis::Core::UploadIO::OCTET_STREAM_CONTENT_TYPE
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should allow overring the mime type' do
|
||||||
|
upload_io = Google::Apis::Core::UploadIO.from_io(io, content_type: 'application/x-gzip')
|
||||||
|
expect(upload_io.content_type).to eq('application/x-gzip')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should allow overriding the mime type' do
|
|
||||||
io = Google::Apis::Core::UploadIO.from_file(file, content_type: 'application/json')
|
|
||||||
expect(io.content_type).to eql('application/json')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue