Sha256: da4e7e6146b0961b281cf3bf5307af9dee4fc7d2e7e75af54c79831943066ab9

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

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.name.should == 'ASCII-8BIT'
        actual.should == data.dup.force_encoding('binary')
      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.name.should == 'UTF-8'
        data.freeze
      end

      it_behaves_like 'round-trips'
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/integration/grid_fs_bucket_spec.rb
mongo-2.17.4 spec/integration/grid_fs_bucket_spec.rb
mongo-2.17.3 spec/integration/grid_fs_bucket_spec.rb
mongo-2.17.2 spec/integration/grid_fs_bucket_spec.rb
mongo-2.16.3 spec/integration/grid_fs_bucket_spec.rb
mongo-2.16.2 spec/integration/grid_fs_bucket_spec.rb
mongo-2.17.1 spec/integration/grid_fs_bucket_spec.rb
mongo-2.16.1 spec/integration/grid_fs_bucket_spec.rb
mongo-2.17.0 spec/integration/grid_fs_bucket_spec.rb
mongo-2.16.0 spec/integration/grid_fs_bucket_spec.rb
mongo-2.15.1 spec/integration/grid_fs_bucket_spec.rb
mongo-2.16.0.alpha1 spec/integration/grid_fs_bucket_spec.rb
mongo-2.15.0 spec/integration/grid_fs_bucket_spec.rb