1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
# frozen_string_literal: true
# rubocop:todo all
require 'spec_helper'
describe 'GridFS bucket integration' do
let(:fs) do
authorized_client.database.fs
end
describe 'UTF-8 string write' do
let(:data) { "hello\u2210" }
before do
data.length.should_not == data.bytesize
end
shared_examples 'round-trips' do
it 'round-trips' do
stream = fs.open_upload_stream('test') do |stream|
stream.write(data_to_write)
end
actual = nil
fs.open_download_stream(stream.file_id) do |stream|
actual = stream.read
end
actual.encoding.should == Encoding::BINARY
actual.should == data.b
end
end
context 'in binary encoding' do
let(:data_to_write) do
data.dup.force_encoding('binary').freeze
end
it_behaves_like 'round-trips'
end
context 'in UTF-8 encoding' do
let(:data_to_write) do
data.encoding.should == Encoding::UTF_8
data.freeze
end
it_behaves_like 'round-trips'
end
end
end
|