bson 2.0.0.beta → 2.0.0.rc
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/LICENSE +190 -0
- data/NOTICE +2 -0
- data/README.md +6 -1
- data/Rakefile +15 -1
- data/ext/bson/native.c +16 -0
- data/lib/bson.rb +12 -50
- data/lib/bson/array.rb +14 -1
- data/lib/bson/binary.rb +14 -1
- data/lib/bson/boolean.rb +14 -1
- data/lib/bson/code.rb +14 -1
- data/lib/bson/code_with_scope.rb +14 -1
- data/lib/bson/document.rb +15 -2
- data/lib/bson/encodable.rb +14 -1
- data/lib/bson/environment.rb +98 -0
- data/lib/bson/false_class.rb +14 -1
- data/lib/bson/float.rb +14 -1
- data/lib/bson/hash.rb +14 -1
- data/lib/bson/int32.rb +15 -2
- data/lib/bson/int64.rb +15 -2
- data/lib/bson/integer.rb +14 -1
- data/lib/bson/json.rb +14 -1
- data/lib/bson/max_key.rb +14 -1
- data/lib/bson/min_key.rb +14 -1
- data/lib/bson/nil_class.rb +14 -1
- data/lib/bson/object_id.rb +15 -2
- data/lib/bson/regexp.rb +14 -1
- data/lib/bson/registry.rb +14 -1
- data/lib/bson/specialized.rb +14 -1
- data/lib/bson/string.rb +14 -1
- data/lib/bson/symbol.rb +14 -1
- data/lib/bson/time.rb +14 -1
- data/lib/bson/timestamp.rb +14 -1
- data/lib/bson/true_class.rb +14 -1
- data/lib/bson/undefined.rb +15 -2
- data/lib/bson/version.rb +15 -2
- data/lib/native.bundle +0 -0
- data/spec/bson/array_spec.rb +31 -0
- data/spec/bson/binary_spec.rb +103 -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 +70 -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 +418 -0
- data/spec/bson/regexp_spec.rb +89 -0
- data/spec/bson/registry_spec.rb +55 -0
- data/spec/bson/string_spec.rb +271 -0
- data/spec/bson/symbol_spec.rb +45 -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/spec/bson_spec.rb +46 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/shared_examples.rb +95 -0
- metadata +85 -5
- metadata.gz.sig +1 -0
- data/LICENSE.md +0 -13
data/lib/bson/object_id.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
require "digest/md5"
|
3
16
|
require "socket"
|
4
17
|
require "thread"
|
@@ -285,7 +298,7 @@ module BSON
|
|
285
298
|
|
286
299
|
private
|
287
300
|
|
288
|
-
if jruby?
|
301
|
+
if Environment.jruby?
|
289
302
|
def process_id
|
290
303
|
"#{Process.pid}#{Thread.current.object_id}".hash % 0xFFFF
|
291
304
|
end
|
data/lib/bson/regexp.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
16
|
|
4
17
|
# Injects behaviour for encoding and decoding regular expression values to
|
data/lib/bson/registry.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
16
|
|
4
17
|
# Provides constant values for each to the BSON types and mappings from raw
|
data/lib/bson/specialized.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
16
|
|
4
17
|
# Provides behaviour to special values that exist in the BSON spec that don't
|
data/lib/bson/string.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
16
|
|
4
17
|
# Injects behaviour for encoding and decoding string values to and from
|
data/lib/bson/symbol.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
16
|
|
4
17
|
# Injects behaviour for encoding and decoding symbol values to and from
|
data/lib/bson/time.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
16
|
|
4
17
|
# Injects behaviour for encoding and decoding time values to
|
data/lib/bson/timestamp.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
16
|
|
4
17
|
# Represents a timestamp type, which is predominately used for sharding.
|
data/lib/bson/true_class.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
16
|
|
4
17
|
# Injects behaviour for encoding and decoding true values to and from
|
data/lib/bson/undefined.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
16
|
|
4
17
|
# Represents the Undefined BSON type
|
@@ -27,7 +40,7 @@ module BSON
|
|
27
40
|
self.class == other.class
|
28
41
|
end
|
29
42
|
|
30
|
-
# Encode the Undefined field - has no value since it only needs the type
|
43
|
+
# Encode the Undefined field - has no value since it only needs the type
|
31
44
|
# and field name when being encoded.
|
32
45
|
#
|
33
46
|
# @example Encode the undefined value.
|
data/lib/bson/version.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
|
2
15
|
module BSON
|
3
|
-
VERSION = "2.0.0.
|
16
|
+
VERSION = "2.0.0.rc"
|
4
17
|
end
|
data/lib/native.bundle
ADDED
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright (C) 2013 10gen 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
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Copyright (C) 2013 10gen 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 "#to_bson/#from_bson" do
|
35
|
+
|
36
|
+
let(:type) { 5.chr }
|
37
|
+
|
38
|
+
it_behaves_like "a bson element"
|
39
|
+
|
40
|
+
context "when the type is :generic" do
|
41
|
+
|
42
|
+
let(:obj) { described_class.new("testing") }
|
43
|
+
let(:bson) { "#{7.to_bson}#{0.chr}testing" }
|
44
|
+
|
45
|
+
it_behaves_like "a serializable bson element"
|
46
|
+
it_behaves_like "a deserializable bson element"
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when the type is :function" do
|
50
|
+
|
51
|
+
let(:obj) { described_class.new("testing", :function) }
|
52
|
+
let(:bson) { "#{7.to_bson}#{1.chr}testing" }
|
53
|
+
|
54
|
+
it_behaves_like "a serializable bson element"
|
55
|
+
it_behaves_like "a deserializable bson element"
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the type is :old" do
|
59
|
+
|
60
|
+
let(:obj) { described_class.new("testing", :old) }
|
61
|
+
let(:bson) { "#{11.to_bson}#{2.chr}#{7.to_bson}testing" }
|
62
|
+
|
63
|
+
it_behaves_like "a serializable bson element"
|
64
|
+
it_behaves_like "a deserializable bson element"
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when the type is :uuid_old" do
|
68
|
+
|
69
|
+
let(:obj) { described_class.new("testing", :uuid_old) }
|
70
|
+
let(:bson) { "#{7.to_bson}#{3.chr}testing" }
|
71
|
+
|
72
|
+
it_behaves_like "a serializable bson element"
|
73
|
+
it_behaves_like "a deserializable bson element"
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when the type is :uuid" do
|
77
|
+
|
78
|
+
let(:obj) { described_class.new("testing", :uuid) }
|
79
|
+
let(:bson) { "#{7.to_bson}#{4.chr}testing" }
|
80
|
+
|
81
|
+
it_behaves_like "a serializable bson element"
|
82
|
+
it_behaves_like "a deserializable bson element"
|
83
|
+
end
|
84
|
+
|
85
|
+
context "when the type is :md5" do
|
86
|
+
|
87
|
+
let(:obj) { described_class.new("testing", :md5) }
|
88
|
+
let(:bson) { "#{7.to_bson}#{5.chr}testing" }
|
89
|
+
|
90
|
+
it_behaves_like "a serializable bson element"
|
91
|
+
it_behaves_like "a deserializable bson element"
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when the type is :user" do
|
95
|
+
|
96
|
+
let(:obj) { described_class.new("testing", :user) }
|
97
|
+
let(:bson) { "#{7.to_bson}#{128.chr}testing" }
|
98
|
+
|
99
|
+
it_behaves_like "a serializable bson element"
|
100
|
+
it_behaves_like "a deserializable bson element"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright (C) 2013 10gen 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
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright (C) 2013 10gen 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::Code do
|
18
|
+
|
19
|
+
describe "#as_json" do
|
20
|
+
|
21
|
+
let(:object) do
|
22
|
+
described_class.new("this.value = 5")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns the binary data plus type" do
|
26
|
+
expect(object.as_json).to eq({ "$code" => "this.value = 5" })
|
27
|
+
end
|
28
|
+
|
29
|
+
it_behaves_like "a JSON serializable object"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#to_bson/#from_bson" do
|
33
|
+
|
34
|
+
let(:type) { 13.chr }
|
35
|
+
let(:obj) { described_class.new("this.value = 5") }
|
36
|
+
let(:bson) { "#{15.to_bson}this.value = 5#{BSON::NULL_BYTE}" }
|
37
|
+
|
38
|
+
it_behaves_like "a bson element"
|
39
|
+
it_behaves_like "a serializable bson element"
|
40
|
+
it_behaves_like "a deserializable bson element"
|
41
|
+
end
|
42
|
+
end
|