bson 1.12.5-java → 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bson might be problematic. Click here for more details.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +80 -0
- data/CONTRIBUTING.md +42 -0
- data/NOTICE +2 -0
- data/README.md +190 -0
- data/Rakefile +109 -0
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson.rb +60 -87
- data/lib/bson/array.rb +104 -0
- data/lib/bson/binary.rb +193 -0
- data/lib/bson/boolean.rb +48 -0
- data/lib/bson/code.rb +109 -0
- data/lib/bson/code_with_scope.rb +120 -0
- data/lib/bson/document.rb +549 -0
- data/lib/bson/encodable.rb +86 -0
- data/lib/bson/environment.rb +98 -0
- data/lib/bson/false_class.rb +61 -0
- data/lib/bson/float.rb +82 -0
- data/lib/bson/hash.rb +84 -0
- data/lib/bson/int32.rb +59 -0
- data/lib/bson/int64.rb +59 -0
- data/lib/bson/integer.rb +185 -0
- data/lib/bson/json.rb +37 -0
- data/lib/bson/max_key.rb +70 -0
- data/lib/bson/min_key.rb +70 -0
- data/lib/bson/nil_class.rb +70 -0
- data/lib/bson/object_id.rb +395 -0
- data/lib/bson/regexp.rb +124 -0
- data/lib/bson/registry.rb +70 -0
- data/lib/bson/specialized.rb +74 -0
- data/lib/bson/string.rb +203 -0
- data/lib/bson/symbol.rb +87 -0
- data/lib/bson/time.rb +72 -0
- data/lib/bson/timestamp.rb +113 -0
- data/lib/bson/true_class.rb +61 -0
- data/lib/bson/undefined.rb +74 -0
- data/lib/bson/version.rb +17 -0
- data/spec/bson/array_spec.rb +58 -0
- data/spec/bson/binary_spec.rb +115 -0
- data/spec/bson/boolean_spec.rb +48 -0
- data/spec/bson/code_spec.rb +42 -0
- data/spec/bson/code_with_scope_spec.rb +74 -0
- data/spec/bson/document_spec.rb +778 -0
- data/spec/bson/false_class_spec.rb +28 -0
- data/spec/bson/float_spec.rb +29 -0
- data/spec/bson/hash_spec.rb +56 -0
- data/spec/bson/int32_spec.rb +28 -0
- data/spec/bson/int64_spec.rb +28 -0
- data/spec/bson/integer_spec.rb +76 -0
- data/spec/bson/json_spec.rb +53 -0
- data/spec/bson/max_key_spec.rb +75 -0
- data/spec/bson/min_key_spec.rb +75 -0
- data/spec/bson/nil_class_spec.rb +29 -0
- data/spec/bson/object_id_spec.rb +527 -0
- data/spec/bson/regexp_spec.rb +89 -0
- data/spec/bson/registry_spec.rb +55 -0
- data/spec/bson/string_spec.rb +298 -0
- data/spec/bson/symbol_spec.rb +55 -0
- data/spec/bson/time_spec.rb +43 -0
- data/spec/bson/timestamp_spec.rb +74 -0
- data/spec/bson/true_class_spec.rb +28 -0
- data/spec/bson/undefined_spec.rb +29 -0
- data/{lib/bson/types/dbref.rb → spec/bson_spec.rb} +22 -16
- data/spec/spec_helper.rb +32 -0
- data/spec/support/shared_examples.rb +95 -0
- metadata +116 -48
- metadata.gz.sig +1 -1
- data/VERSION +0 -1
- data/bin/b2json +0 -63
- data/bin/j2bson +0 -64
- data/bson.gemspec +0 -34
- data/ext/jbson/lib/java-bson.jar +0 -0
- data/ext/jbson/target/jbson.jar +0 -0
- data/lib/bson/bson_c.rb +0 -37
- data/lib/bson/bson_java.rb +0 -49
- data/lib/bson/bson_ruby.rb +0 -645
- data/lib/bson/byte_buffer.rb +0 -241
- data/lib/bson/exceptions.rb +0 -37
- data/lib/bson/grow.rb +0 -173
- data/lib/bson/ordered_hash.rb +0 -197
- data/lib/bson/support/hash_with_indifferent_access.rb +0 -174
- data/lib/bson/types/binary.rb +0 -52
- data/lib/bson/types/code.rb +0 -55
- data/lib/bson/types/min_max_keys.rb +0 -56
- data/lib/bson/types/object_id.rb +0 -226
- data/lib/bson/types/regex.rb +0 -116
- data/lib/bson/types/timestamp.rb +0 -72
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module BSON
|
16
|
+
|
17
|
+
# Represents a timestamp type, which is predominately used for sharding.
|
18
|
+
#
|
19
|
+
# @see http://bsonspec.org/#/specification
|
20
|
+
#
|
21
|
+
# @since 2.0.0
|
22
|
+
class Timestamp
|
23
|
+
include JSON
|
24
|
+
|
25
|
+
# A timestamp is type 0x11 in the BSON spec.
|
26
|
+
#
|
27
|
+
# @since 2.0.0
|
28
|
+
BSON_TYPE = 17.chr.force_encoding(BINARY).freeze
|
29
|
+
|
30
|
+
# @!attribute seconds
|
31
|
+
# @return [ Integer ] The number of seconds.
|
32
|
+
# @since 2.0.0
|
33
|
+
#
|
34
|
+
# @!attribute increment
|
35
|
+
# @return [ Integer ] The incrementing value.
|
36
|
+
# @since 2.0.0
|
37
|
+
#
|
38
|
+
attr_reader :seconds, :increment
|
39
|
+
|
40
|
+
# Determine if this timestamp is equal to another object.
|
41
|
+
#
|
42
|
+
# @example Check the timestamp equality.
|
43
|
+
# timestamp == other
|
44
|
+
#
|
45
|
+
# @param [ Object ] other The object to compare against.
|
46
|
+
#
|
47
|
+
# @return [ true, false ] If the objects are equal.
|
48
|
+
#
|
49
|
+
# @since 2.0.0
|
50
|
+
def ==(other)
|
51
|
+
return false unless other.is_a?(Timestamp)
|
52
|
+
seconds == other.seconds && increment == other.increment
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get the timestamp as JSON hash data.
|
56
|
+
#
|
57
|
+
# @example Get the timestamp as a JSON hash.
|
58
|
+
# timestamp.as_json
|
59
|
+
#
|
60
|
+
# @return [ Hash ] The timestamp as a JSON hash.
|
61
|
+
#
|
62
|
+
# @since 2.0.0
|
63
|
+
def as_json(*args)
|
64
|
+
{ "t" => seconds, "i" => increment }
|
65
|
+
end
|
66
|
+
|
67
|
+
# Instantiate the new timestamp.
|
68
|
+
#
|
69
|
+
# @example Instantiate the timestamp.
|
70
|
+
# BSON::Timestamp.new(5, 30)
|
71
|
+
#
|
72
|
+
# @param [ Integer ] seconds The number of seconds.
|
73
|
+
# @param [ Integer ] increment The increment value.
|
74
|
+
#
|
75
|
+
# @since 2.0.0
|
76
|
+
def initialize(seconds, increment)
|
77
|
+
@seconds, @increment = seconds, increment
|
78
|
+
end
|
79
|
+
|
80
|
+
# Get the timestamp as its encoded raw BSON bytes.
|
81
|
+
#
|
82
|
+
# @example Get the timestamp as BSON.
|
83
|
+
# timestamp.to_bson
|
84
|
+
#
|
85
|
+
# @return [ String ] The raw BSON bytes.
|
86
|
+
#
|
87
|
+
# @see http://bsonspec.org/#/specification
|
88
|
+
#
|
89
|
+
# @since 2.0.0
|
90
|
+
def to_bson(encoded = ''.force_encoding(BINARY))
|
91
|
+
increment.to_bson_int32(encoded)
|
92
|
+
seconds.to_bson_int32(encoded)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Deserialize timestamp from BSON.
|
96
|
+
#
|
97
|
+
# @param [ BSON ] bson The bson representing a timestamp.
|
98
|
+
#
|
99
|
+
# @return [ Timestamp ] The decoded timestamp.
|
100
|
+
#
|
101
|
+
# @see http://bsonspec.org/#/specification
|
102
|
+
#
|
103
|
+
# @since 2.0.0
|
104
|
+
def self.from_bson(bson)
|
105
|
+
new(*bson.read(8).unpack(Int32::PACK * 2).reverse)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Register this type when the module is loaded.
|
109
|
+
#
|
110
|
+
# @since 2.0.0
|
111
|
+
Registry.register(BSON_TYPE, self)
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module BSON
|
16
|
+
|
17
|
+
# Injects behaviour for encoding and decoding true values to and from
|
18
|
+
# raw bytes as specified by the BSON spec.
|
19
|
+
#
|
20
|
+
# @see http://bsonspec.org/#/specification
|
21
|
+
#
|
22
|
+
# @since 2.0.0
|
23
|
+
module TrueClass
|
24
|
+
|
25
|
+
# A true value in the BSON spec is 0x01.
|
26
|
+
#
|
27
|
+
# @since 2.0.0
|
28
|
+
TRUE_BYTE = 1.chr.force_encoding(BINARY).freeze
|
29
|
+
|
30
|
+
# The BSON type for true values is the general boolean type of 0x08.
|
31
|
+
#
|
32
|
+
# @example Get the bson type.
|
33
|
+
# false.bson_type
|
34
|
+
#
|
35
|
+
# @return [ String ] The character 0x08.
|
36
|
+
#
|
37
|
+
# @since 2.0.0
|
38
|
+
def bson_type
|
39
|
+
Boolean::BSON_TYPE
|
40
|
+
end
|
41
|
+
|
42
|
+
# Get the true boolean as encoded BSON.
|
43
|
+
#
|
44
|
+
# @example Get the true boolean as encoded BSON.
|
45
|
+
# true.to_bson
|
46
|
+
#
|
47
|
+
# @return [ String ] The encoded string.
|
48
|
+
#
|
49
|
+
# @see http://bsonspec.org/#/specification
|
50
|
+
#
|
51
|
+
# @since 2.0.0
|
52
|
+
def to_bson(encoded = ''.force_encoding(BINARY))
|
53
|
+
encoded << TRUE_BYTE
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Enrich the core TrueClass class with this module.
|
58
|
+
#
|
59
|
+
# @since 2.0.0
|
60
|
+
::TrueClass.send(:include, TrueClass)
|
61
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module BSON
|
16
|
+
|
17
|
+
# Represents the Undefined BSON type
|
18
|
+
#
|
19
|
+
# @see http://bsonspec.org/#/specification
|
20
|
+
#
|
21
|
+
# @since 2.0.0
|
22
|
+
class Undefined
|
23
|
+
|
24
|
+
# Undefined is type 0x06 in the BSON spec.
|
25
|
+
#
|
26
|
+
# @since 2.0.0
|
27
|
+
BSON_TYPE = 6.chr.force_encoding(BINARY).freeze
|
28
|
+
|
29
|
+
# Determine if undefined is equal to another object.
|
30
|
+
#
|
31
|
+
# @example Check undefined equality.
|
32
|
+
# BSON::Undefined.new == object
|
33
|
+
#
|
34
|
+
# @param [ Object ] other The object to check against.
|
35
|
+
#
|
36
|
+
# @return [ true, false ] If the objects are equal.
|
37
|
+
#
|
38
|
+
# @since 2.0.0
|
39
|
+
def ==(other)
|
40
|
+
self.class == other.class
|
41
|
+
end
|
42
|
+
|
43
|
+
# Encode the Undefined field - has no value since it only needs the type
|
44
|
+
# and field name when being encoded.
|
45
|
+
#
|
46
|
+
# @example Encode the undefined value.
|
47
|
+
# Undefined.to_bson
|
48
|
+
#
|
49
|
+
# @return [ String ] An empty string.
|
50
|
+
#
|
51
|
+
# @since 2.0.0
|
52
|
+
def to_bson(encoded = ''.force_encoding(BINARY))
|
53
|
+
encoded
|
54
|
+
end
|
55
|
+
|
56
|
+
# Deserialize undefined BSON type from BSON.
|
57
|
+
#
|
58
|
+
# @param [ BSON ] bson The encoded undefined value.
|
59
|
+
#
|
60
|
+
# @return [ Undefined ] The decoded undefined value.
|
61
|
+
#
|
62
|
+
# @see http://bsonspec.org/#/specification
|
63
|
+
#
|
64
|
+
# @since 2.0.0
|
65
|
+
def self.from_bson(bson)
|
66
|
+
new
|
67
|
+
end
|
68
|
+
|
69
|
+
# Register this type when the module is loaded.
|
70
|
+
#
|
71
|
+
# @since 2.0.0
|
72
|
+
Registry.register(BSON_TYPE, self)
|
73
|
+
end
|
74
|
+
end
|
data/lib/bson/version.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module BSON
|
16
|
+
VERSION = "2.0.0"
|
17
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "spec_helper"
|
16
|
+
|
17
|
+
describe Array do
|
18
|
+
|
19
|
+
describe "#to_bson/#from_bson" do
|
20
|
+
|
21
|
+
let(:type) { 4.chr }
|
22
|
+
let(:obj) {[ "one", "two" ]}
|
23
|
+
let(:bson) do
|
24
|
+
BSON::Document["0", "one", "1", "two"].to_bson
|
25
|
+
end
|
26
|
+
|
27
|
+
it_behaves_like "a bson element"
|
28
|
+
it_behaves_like "a serializable bson element"
|
29
|
+
it_behaves_like "a deserializable bson element"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#to_bson_object_id" do
|
33
|
+
|
34
|
+
context "when the array has 12 elements" do
|
35
|
+
|
36
|
+
let(:array) do
|
37
|
+
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:converted) do
|
41
|
+
array.to_bson_object_id
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the array as a string" do
|
45
|
+
expect(converted).to eq(array.pack("C*"))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when the array does not have 12 elements" do
|
50
|
+
|
51
|
+
it "raises an exception" do
|
52
|
+
expect {
|
53
|
+
[ 1 ].to_bson_object_id
|
54
|
+
}.to raise_error(BSON::ObjectId::Invalid)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "spec_helper"
|
16
|
+
|
17
|
+
describe BSON::Binary do
|
18
|
+
|
19
|
+
describe "#as_json" do
|
20
|
+
|
21
|
+
let(:object) do
|
22
|
+
described_class.new("testing", :user)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns the binary data plus type" do
|
26
|
+
expect(object.as_json).to eq(
|
27
|
+
{ "$binary" => "testing", "$type" => :user }
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it_behaves_like "a JSON serializable object"
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#initialize" do
|
35
|
+
|
36
|
+
context "when he type is invalid" do
|
37
|
+
|
38
|
+
it "raises an error" do
|
39
|
+
expect {
|
40
|
+
described_class.new("testing", :error)
|
41
|
+
}.to raise_error(BSON::Binary::InvalidType)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#to_bson/#from_bson" do
|
47
|
+
|
48
|
+
let(:type) { 5.chr }
|
49
|
+
|
50
|
+
it_behaves_like "a bson element"
|
51
|
+
|
52
|
+
context "when the type is :generic" do
|
53
|
+
|
54
|
+
let(:obj) { described_class.new("testing") }
|
55
|
+
let(:bson) { "#{7.to_bson}#{0.chr}testing" }
|
56
|
+
|
57
|
+
it_behaves_like "a serializable bson element"
|
58
|
+
it_behaves_like "a deserializable bson element"
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when the type is :function" do
|
62
|
+
|
63
|
+
let(:obj) { described_class.new("testing", :function) }
|
64
|
+
let(:bson) { "#{7.to_bson}#{1.chr}testing" }
|
65
|
+
|
66
|
+
it_behaves_like "a serializable bson element"
|
67
|
+
it_behaves_like "a deserializable bson element"
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when the type is :old" do
|
71
|
+
|
72
|
+
let(:obj) { described_class.new("testing", :old) }
|
73
|
+
let(:bson) { "#{11.to_bson}#{2.chr}#{7.to_bson}testing" }
|
74
|
+
|
75
|
+
it_behaves_like "a serializable bson element"
|
76
|
+
it_behaves_like "a deserializable bson element"
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when the type is :uuid_old" do
|
80
|
+
|
81
|
+
let(:obj) { described_class.new("testing", :uuid_old) }
|
82
|
+
let(:bson) { "#{7.to_bson}#{3.chr}testing" }
|
83
|
+
|
84
|
+
it_behaves_like "a serializable bson element"
|
85
|
+
it_behaves_like "a deserializable bson element"
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when the type is :uuid" do
|
89
|
+
|
90
|
+
let(:obj) { described_class.new("testing", :uuid) }
|
91
|
+
let(:bson) { "#{7.to_bson}#{4.chr}testing" }
|
92
|
+
|
93
|
+
it_behaves_like "a serializable bson element"
|
94
|
+
it_behaves_like "a deserializable bson element"
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when the type is :md5" do
|
98
|
+
|
99
|
+
let(:obj) { described_class.new("testing", :md5) }
|
100
|
+
let(:bson) { "#{7.to_bson}#{5.chr}testing" }
|
101
|
+
|
102
|
+
it_behaves_like "a serializable bson element"
|
103
|
+
it_behaves_like "a deserializable bson element"
|
104
|
+
end
|
105
|
+
|
106
|
+
context "when the type is :user" do
|
107
|
+
|
108
|
+
let(:obj) { described_class.new("testing", :user) }
|
109
|
+
let(:bson) { "#{7.to_bson}#{128.chr}testing" }
|
110
|
+
|
111
|
+
it_behaves_like "a serializable bson element"
|
112
|
+
it_behaves_like "a deserializable bson element"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "spec_helper"
|
16
|
+
|
17
|
+
describe BSON::Boolean do
|
18
|
+
|
19
|
+
describe "::BSON_TYPE" do
|
20
|
+
|
21
|
+
it "returns 8" do
|
22
|
+
expect(BSON::Boolean::BSON_TYPE).to eq(8.chr)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#from_bson" do
|
27
|
+
|
28
|
+
let(:type) { 8.chr }
|
29
|
+
|
30
|
+
it_behaves_like "a bson element"
|
31
|
+
|
32
|
+
context "when the boolean is true" do
|
33
|
+
|
34
|
+
let(:obj) { true }
|
35
|
+
let(:bson) { 1.chr }
|
36
|
+
|
37
|
+
it_behaves_like "a deserializable bson element"
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when the boolean is false" do
|
41
|
+
|
42
|
+
let(:obj) { false }
|
43
|
+
let(:bson) { 0.chr }
|
44
|
+
|
45
|
+
it_behaves_like "a deserializable bson element"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|