Sha256: 89b54a7ced8df6ac00e4eede0c518b079785f8c2274d3fed0d85fb7f90ed4308

Contents?: true

Size: 1.48 KB

Versions: 24

Compression:

Stored size: 1.48 KB

Contents

# Copyright (C) 2009-2014 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "spec_helper"

describe Array do

  describe "#to_bson/#from_bson" do

    let(:type) { 4.chr }
    let(:obj)  {[ "one", "two" ]}
    let(:bson) do
      BSON::Document["0", "one", "1", "two"].to_bson
    end

    it_behaves_like "a bson element"
    it_behaves_like "a serializable bson element"
    it_behaves_like "a deserializable bson element"
  end

  describe "#to_bson_object_id" do

    context "when the array has 12 elements" do

      let(:array) do
        [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
      end

      let(:converted) do
        array.to_bson_object_id
      end

      it "returns the array as a string" do
        expect(converted).to eq(array.pack("C*"))
      end
    end

    context "when the array does not have 12 elements" do

      it "raises an exception" do
        expect {
          [ 1 ].to_bson_object_id
        }.to raise_error(BSON::ObjectId::Invalid)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
bson-3.2.1-java spec/bson/array_spec.rb
bson-3.2.1 spec/bson/array_spec.rb
bson-3.2.0-java spec/bson/array_spec.rb
bson-3.2.0 spec/bson/array_spec.rb
bson-3.1.2-java spec/bson/array_spec.rb
bson-3.1.2 spec/bson/array_spec.rb
bson-3.1.1-java spec/bson/array_spec.rb
bson-3.1.1 spec/bson/array_spec.rb
bson-3.1.0-java spec/bson/array_spec.rb
bson-3.1.0 spec/bson/array_spec.rb
bson-3.0.4-java spec/bson/array_spec.rb
bson-3.0.4 spec/bson/array_spec.rb
bson-3.0.3-java spec/bson/array_spec.rb
bson-3.0.3 spec/bson/array_spec.rb
bson-3.0.2-java spec/bson/array_spec.rb
bson-3.0.2 spec/bson/array_spec.rb
bson-3.0.1-java spec/bson/array_spec.rb
bson-3.0.1 spec/bson/array_spec.rb
bson-3.0.0-java spec/bson/array_spec.rb
bson-3.0.0 spec/bson/array_spec.rb