mongo 2.18.1 → 2.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/mongo/bulk_write.rb +6 -4
- data/lib/mongo/client.rb +1 -1
- data/lib/mongo/collection/view/writable.rb +0 -2
- data/lib/mongo/collection.rb +150 -45
- data/lib/mongo/crypt/kms.rb +0 -1
- data/lib/mongo/error/invalid_read_option.rb +1 -1
- data/lib/mongo/operation/aggregate.rb +1 -2
- data/lib/mongo/operation/collections_info.rb +3 -15
- data/lib/mongo/operation/command.rb +1 -2
- data/lib/mongo/operation/count.rb +1 -2
- data/lib/mongo/operation/create.rb +1 -2
- data/lib/mongo/operation/create_index.rb +1 -2
- data/lib/mongo/operation/create_user.rb +1 -2
- data/lib/mongo/operation/delete.rb +0 -1
- data/lib/mongo/operation/distinct.rb +1 -2
- data/lib/mongo/operation/drop.rb +1 -2
- data/lib/mongo/operation/drop_database.rb +1 -2
- data/lib/mongo/operation/drop_index.rb +1 -2
- data/lib/mongo/operation/explain.rb +1 -3
- data/lib/mongo/operation/find/builder.rb +0 -1
- data/lib/mongo/operation/find.rb +1 -3
- data/lib/mongo/operation/get_more.rb +1 -3
- data/lib/mongo/operation/indexes.rb +1 -17
- data/lib/mongo/operation/insert.rb +0 -1
- data/lib/mongo/operation/kill_cursors.rb +1 -2
- data/lib/mongo/operation/list_collections.rb +1 -2
- data/lib/mongo/operation/map_reduce.rb +1 -2
- data/lib/mongo/operation/parallel_scan.rb +1 -2
- data/lib/mongo/operation/remove_user.rb +1 -2
- data/lib/mongo/operation/shared/{polymorphic_operation.rb → op_msg_executable.rb} +11 -6
- data/lib/mongo/operation/update.rb +0 -1
- data/lib/mongo/operation/update_user.rb +1 -2
- data/lib/mongo/operation/users_info.rb +1 -2
- data/lib/mongo/operation/write_command.rb +1 -2
- data/lib/mongo/operation.rb +1 -3
- data/lib/mongo/protocol.rb +0 -3
- data/lib/mongo/query_cache.rb +20 -20
- data/lib/mongo/session.rb +1 -1
- data/lib/mongo/version.rb +1 -1
- data/spec/integration/command_spec.rb +1 -23
- data/spec/mongo/client_construction_spec.rb +4 -4
- data/spec/mongo/collection_crud_spec.rb +56 -0
- data/spec/mongo/collection_spec.rb +11 -1
- data/spec/mongo/crypt/kms_spec.rb +12 -9
- data.tar.gz.sig +0 -0
- metadata +1133 -1186
- metadata.gz.sig +0 -0
- data/lib/mongo/operation/aggregate/command.rb +0 -55
- data/lib/mongo/operation/collections_info/command.rb +0 -48
- data/lib/mongo/operation/command/command.rb +0 -41
- data/lib/mongo/operation/count/command.rb +0 -47
- data/lib/mongo/operation/create/command.rb +0 -47
- data/lib/mongo/operation/create_index/command.rb +0 -61
- data/lib/mongo/operation/create_user/command.rb +0 -46
- data/lib/mongo/operation/delete/command.rb +0 -52
- data/lib/mongo/operation/distinct/command.rb +0 -47
- data/lib/mongo/operation/drop/command.rb +0 -41
- data/lib/mongo/operation/drop_database/command.rb +0 -41
- data/lib/mongo/operation/drop_index/command.rb +0 -45
- data/lib/mongo/operation/explain/command.rb +0 -58
- data/lib/mongo/operation/explain/legacy.rb +0 -52
- data/lib/mongo/operation/find/builder/legacy.rb +0 -123
- data/lib/mongo/operation/find/command.rb +0 -51
- data/lib/mongo/operation/find/legacy/result.rb +0 -46
- data/lib/mongo/operation/find/legacy.rb +0 -52
- data/lib/mongo/operation/get_more/command.rb +0 -43
- data/lib/mongo/operation/get_more/legacy.rb +0 -39
- data/lib/mongo/operation/indexes/command.rb +0 -42
- data/lib/mongo/operation/indexes/legacy.rb +0 -48
- data/lib/mongo/operation/insert/command.rb +0 -55
- data/lib/mongo/operation/kill_cursors/command.rb +0 -48
- data/lib/mongo/operation/list_collections/command.rb +0 -46
- data/lib/mongo/operation/map_reduce/command.rb +0 -51
- data/lib/mongo/operation/parallel_scan/command.rb +0 -57
- data/lib/mongo/operation/remove_user/command.rb +0 -46
- data/lib/mongo/operation/shared/op_msg_or_command.rb +0 -41
- data/lib/mongo/operation/shared/op_msg_or_find_command.rb +0 -44
- data/lib/mongo/operation/update/command.rb +0 -53
- data/lib/mongo/operation/update_user/command.rb +0 -45
- data/lib/mongo/operation/users_info/command.rb +0 -46
- data/lib/mongo/operation/write_command/command.rb +0 -51
- data/lib/mongo/protocol/delete.rb +0 -172
- data/lib/mongo/protocol/insert.rb +0 -181
- data/lib/mongo/protocol/update.rb +0 -214
- data/spec/mongo/operation/delete/command_spec.rb +0 -115
- data/spec/mongo/operation/find/legacy_spec.rb +0 -131
- data/spec/mongo/operation/get_more_spec.rb +0 -63
- data/spec/mongo/operation/insert/command_spec.rb +0 -118
- data/spec/mongo/operation/update/command_spec.rb +0 -122
- data/spec/mongo/protocol/delete_spec.rb +0 -185
- data/spec/mongo/protocol/insert_spec.rb +0 -179
- data/spec/mongo/protocol/update_spec.rb +0 -204
@@ -1,118 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'spec_helper'
|
5
|
-
|
6
|
-
describe Mongo::Operation::Insert::Command do
|
7
|
-
|
8
|
-
let(:documents) { [{ :_id => 1, :foo => 1 }] }
|
9
|
-
let(:session) { nil }
|
10
|
-
let(:spec) do
|
11
|
-
{ :documents => documents,
|
12
|
-
:db_name => authorized_collection.database.name,
|
13
|
-
:coll_name => authorized_collection.name,
|
14
|
-
:write_concern => write_concern,
|
15
|
-
:ordered => true,
|
16
|
-
:session => session
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:write_concern) do
|
21
|
-
Mongo::WriteConcern.get(w: :majority)
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:op) { described_class.new(spec) }
|
25
|
-
|
26
|
-
describe '#initialize' do
|
27
|
-
|
28
|
-
context 'spec' do
|
29
|
-
|
30
|
-
it 'sets the spec' do
|
31
|
-
expect(op.spec).to eq(spec)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#==' do
|
37
|
-
|
38
|
-
context 'spec' do
|
39
|
-
|
40
|
-
context 'when two ops have the same specs' do
|
41
|
-
let(:other) { described_class.new(spec) }
|
42
|
-
|
43
|
-
it 'returns true' do
|
44
|
-
expect(op).to eq(other)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when two ops have different specs' do
|
49
|
-
let(:other_documents) { [{ :bar => 1 }] }
|
50
|
-
let(:other_spec) do
|
51
|
-
{ :documents => other_documents,
|
52
|
-
:db_name => authorized_collection.database.name,
|
53
|
-
:insert => authorized_collection.name,
|
54
|
-
:write_concern => write_concern.options,
|
55
|
-
:ordered => true
|
56
|
-
}
|
57
|
-
end
|
58
|
-
let(:other) { described_class.new(other_spec) }
|
59
|
-
|
60
|
-
it 'returns false' do
|
61
|
-
expect(op).not_to eq(other)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe 'write concern' do
|
68
|
-
# https://jira.mongodb.org/browse/RUBY-2224
|
69
|
-
require_no_linting
|
70
|
-
|
71
|
-
context 'when write concern is not specified' do
|
72
|
-
|
73
|
-
let(:spec) do
|
74
|
-
{ :documents => documents,
|
75
|
-
:db_name => authorized_collection.database.name,
|
76
|
-
:coll_name => authorized_collection.name,
|
77
|
-
:ordered => true
|
78
|
-
}
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'does not include write concern in the selector' do
|
82
|
-
expect(op.send(:command, double('server'))[:writeConcern]).to be_nil
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when write concern is specified' do
|
87
|
-
|
88
|
-
it 'includes write concern in the selector' do
|
89
|
-
expect(op.send(:command, double('server'))[:writeConcern]).to eq(write_concern.options)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe '#message' do
|
95
|
-
# https://jira.mongodb.org/browse/RUBY-2224
|
96
|
-
require_no_linting
|
97
|
-
|
98
|
-
context 'when the server does not support OP_MSG' do
|
99
|
-
max_server_version '3.4'
|
100
|
-
|
101
|
-
let(:expected_selector) do
|
102
|
-
{ :documents => documents,
|
103
|
-
:insert => authorized_collection.name,
|
104
|
-
:writeConcern => write_concern.options,
|
105
|
-
:ordered => true
|
106
|
-
}
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'creates a query wire protocol message with correct specs' do
|
110
|
-
expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name,
|
111
|
-
'$cmd',
|
112
|
-
expected_selector,
|
113
|
-
{ limit: -1, validating_keys: true })
|
114
|
-
op.send(:message, authorized_primary)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'spec_helper'
|
5
|
-
|
6
|
-
describe Mongo::Operation::Update::Command do
|
7
|
-
|
8
|
-
let(:updates) { [{:q => { :foo => 1 },
|
9
|
-
:u => { :$set => { :bar => 1 } },
|
10
|
-
:multi => true,
|
11
|
-
:upsert => false }] }
|
12
|
-
|
13
|
-
let(:write_concern) do
|
14
|
-
Mongo::WriteConcern.get(w: :majority)
|
15
|
-
end
|
16
|
-
let(:session) { nil }
|
17
|
-
let(:spec) do
|
18
|
-
{ :updates => updates,
|
19
|
-
:db_name => SpecConfig.instance.test_db,
|
20
|
-
:coll_name => TEST_COLL,
|
21
|
-
:write_concern => write_concern,
|
22
|
-
:ordered => true,
|
23
|
-
:session => session
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
let(:op) { described_class.new(spec) }
|
28
|
-
|
29
|
-
describe '#initialize' do
|
30
|
-
|
31
|
-
context 'spec' do
|
32
|
-
|
33
|
-
it 'sets the spec' do
|
34
|
-
expect(op.spec).to eq(spec)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#==' do
|
40
|
-
|
41
|
-
context 'spec' do
|
42
|
-
|
43
|
-
context 'when two ops have the same specs' do
|
44
|
-
let(:other) { described_class.new(spec) }
|
45
|
-
|
46
|
-
it 'returns true' do
|
47
|
-
expect(op).to eq(other)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'when two ops have different specs' do
|
52
|
-
let(:other_updates) { [{:q => { :bar => 1 },
|
53
|
-
:u => { :$set => { :bar => 2 } },
|
54
|
-
:multi => true,
|
55
|
-
:upsert => false }] }
|
56
|
-
let(:other_spec) do
|
57
|
-
{ :updates => other_updates,
|
58
|
-
:db_name => SpecConfig.instance.test_db,
|
59
|
-
:coll_name => TEST_COLL,
|
60
|
-
:write_concern => Mongo::WriteConcern.get(w: :majority),
|
61
|
-
:ordered => true
|
62
|
-
}
|
63
|
-
end
|
64
|
-
let(:other) { described_class.new(other_spec) }
|
65
|
-
|
66
|
-
it 'returns false' do
|
67
|
-
expect(op).not_to eq(other)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'write concern' do
|
74
|
-
# https://jira.mongodb.org/browse/RUBY-2224
|
75
|
-
require_no_linting
|
76
|
-
|
77
|
-
context 'when write concern is not specified' do
|
78
|
-
|
79
|
-
let(:spec) do
|
80
|
-
{ :updates => updates,
|
81
|
-
:db_name => SpecConfig.instance.test_db,
|
82
|
-
:coll_name => TEST_COLL,
|
83
|
-
:ordered => true
|
84
|
-
}
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'does not include write concern in the selector' do
|
88
|
-
expect(op.send(:command, double('server'))[:writeConcern]).to be_nil
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'when write concern is specified' do
|
93
|
-
|
94
|
-
it 'includes write concern in the selector' do
|
95
|
-
expect(op.send(:command, double('server'))[:writeConcern]).to eq(write_concern.options)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe '#message' do
|
101
|
-
# https://jira.mongodb.org/browse/RUBY-2224
|
102
|
-
require_no_linting
|
103
|
-
|
104
|
-
context 'when the server does not support OP_MSG' do
|
105
|
-
max_server_version '3.4'
|
106
|
-
|
107
|
-
let(:expected_selector) do
|
108
|
-
{
|
109
|
-
:update => TEST_COLL,
|
110
|
-
:updates => updates,
|
111
|
-
:ordered => true,
|
112
|
-
:writeConcern => write_concern.options
|
113
|
-
}
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'creates the correct Command message' do
|
117
|
-
expect(Mongo::Protocol::Query).to receive(:new).with(SpecConfig.instance.test_db, '$cmd', expected_selector, { limit: -1 })
|
118
|
-
op.send(:message, authorized_primary)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,185 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'lite_spec_helper'
|
5
|
-
require 'support/shared/protocol'
|
6
|
-
|
7
|
-
describe Mongo::Protocol::Delete do
|
8
|
-
|
9
|
-
let(:opcode) { 2006 }
|
10
|
-
let(:db) { SpecConfig.instance.test_db }
|
11
|
-
let(:collection_name) { 'protocol-test' }
|
12
|
-
let(:ns) { "#{db}.#{collection_name}" }
|
13
|
-
let(:selector) { { :name => 'Tyler' } }
|
14
|
-
let(:options) { Hash.new }
|
15
|
-
|
16
|
-
let(:message) do
|
17
|
-
described_class.new(db, collection_name, selector, options)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#initialize' do
|
21
|
-
|
22
|
-
it 'sets the namepsace' do
|
23
|
-
expect(message.namespace).to eq(ns)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'sets the selector' do
|
27
|
-
expect(message.selector).to eq(selector)
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'when options are provided' do
|
31
|
-
|
32
|
-
context 'when flags are provided' do
|
33
|
-
let(:options) { { :flags => [:single_remove] } }
|
34
|
-
|
35
|
-
it 'sets the flags' do
|
36
|
-
expect(message.flags).to eq(options[:flags])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '#==' do
|
43
|
-
|
44
|
-
context 'when the other is a delete' do
|
45
|
-
|
46
|
-
context 'when the fields are equal' do
|
47
|
-
let(:other) do
|
48
|
-
described_class.new(db, collection_name, selector, options)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'returns true' do
|
52
|
-
expect(message).to eq(other)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'when the database is not equal' do
|
57
|
-
let(:other) do
|
58
|
-
described_class.new('tyler', collection_name, selector, options)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'returns false' do
|
62
|
-
expect(message).not_to eq(other)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when the collection is not equal' do
|
67
|
-
let(:other) do
|
68
|
-
described_class.new(db, 'tyler', selector, options)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'returns false' do
|
72
|
-
expect(message).not_to eq(other)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'when the selector is not equal' do
|
77
|
-
let(:other) do
|
78
|
-
described_class.new(db, collection_name, { :a => 1 }, options)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'returns false' do
|
82
|
-
expect(message).not_to eq(other)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when the options are not equal' do
|
87
|
-
let(:other) do
|
88
|
-
described_class.new(db, collection_name, selector, :flags => [:single_remove])
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'returns false' do
|
92
|
-
expect(message).not_to eq(other)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when the other is not a delete' do
|
98
|
-
let(:other) do
|
99
|
-
expect(message).not_to eq('test')
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe '#hash' do
|
105
|
-
let(:values) do
|
106
|
-
message.send(:fields).map do |field|
|
107
|
-
message.instance_variable_get(field[:name])
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'returns a hash of the field values' do
|
112
|
-
expect(message.hash).to eq(values.hash)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
describe '#replyable?' do
|
117
|
-
|
118
|
-
it 'returns false' do
|
119
|
-
expect(message).to_not be_replyable
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe '#serialize' do
|
124
|
-
let(:bytes) { message.serialize }
|
125
|
-
|
126
|
-
include_examples 'message with a header'
|
127
|
-
|
128
|
-
describe 'zero' do
|
129
|
-
let(:field) { bytes.to_s[16..19] }
|
130
|
-
|
131
|
-
it 'serializes a zero' do
|
132
|
-
expect(field).to be_int32(0)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
describe 'namespace' do
|
137
|
-
let(:field) { bytes.to_s[20..36] }
|
138
|
-
it 'serializes the namespace' do
|
139
|
-
expect(field).to be_cstring(ns)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe 'flags' do
|
144
|
-
let(:field) { bytes.to_s[37..40] }
|
145
|
-
|
146
|
-
context 'when no flags are provided' do
|
147
|
-
it 'does not set any bits' do
|
148
|
-
expect(field).to be_int32(0)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context 'when flags are provided' do
|
153
|
-
let(:options) { { :flags => flags } }
|
154
|
-
|
155
|
-
context 'single remove flag' do
|
156
|
-
let(:flags) { [:single_remove] }
|
157
|
-
it 'sets the first bit' do
|
158
|
-
expect(field).to be_int32(1)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
describe 'selector' do
|
165
|
-
let(:field) { bytes.to_s[41..-1] }
|
166
|
-
it 'serializes the selector' do
|
167
|
-
expect(field).to be_bson(selector)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe '#registry' do
|
173
|
-
|
174
|
-
context 'when the class is loaded' do
|
175
|
-
|
176
|
-
it 'registers the op code in the Protocol Registry' do
|
177
|
-
expect(Mongo::Protocol::Registry.get(described_class::OP_CODE)).to be(described_class)
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'creates an #op_code instance method' do
|
181
|
-
expect(message.op_code).to eq(described_class::OP_CODE)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
@@ -1,179 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'lite_spec_helper'
|
5
|
-
require 'support/shared/protocol'
|
6
|
-
|
7
|
-
describe Mongo::Protocol::Insert do
|
8
|
-
|
9
|
-
let(:opcode) { 2002 }
|
10
|
-
let(:db) { SpecConfig.instance.test_db }
|
11
|
-
let(:collection_name) { 'protocol-test' }
|
12
|
-
let(:ns) { "#{db}.#{collection_name}" }
|
13
|
-
let(:doc1) { { :name => 'Tyler' } }
|
14
|
-
let(:doc2) { { :name => 'Brandon' } }
|
15
|
-
let(:docs) { [doc1, doc2] }
|
16
|
-
let(:options) { Hash.new }
|
17
|
-
|
18
|
-
let(:message) do
|
19
|
-
described_class.new(db, collection_name, docs, options)
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#initialize' do
|
23
|
-
|
24
|
-
it 'sets the namepsace' do
|
25
|
-
expect(message.namespace).to eq(ns)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'sets the documents' do
|
29
|
-
expect(message.documents).to eq(docs)
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when options are provided' do
|
33
|
-
|
34
|
-
context 'when flags are provided' do
|
35
|
-
let(:options) { { :flags => [:continue_on_error] } }
|
36
|
-
|
37
|
-
it 'sets the flags' do
|
38
|
-
expect(message.flags).to eq(options[:flags])
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#==' do
|
45
|
-
|
46
|
-
context 'when the other is an insert' do
|
47
|
-
|
48
|
-
context 'when the fields are equal' do
|
49
|
-
let(:other) do
|
50
|
-
described_class.new(db, collection_name, docs, options)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'returns true' do
|
54
|
-
expect(message).to eq(other)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'when the database is not equal' do
|
59
|
-
let(:other) do
|
60
|
-
described_class.new('tyler', collection_name, docs, options)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'returns false' do
|
64
|
-
expect(message).not_to eq(other)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'when the collection is not equal' do
|
69
|
-
let(:other) do
|
70
|
-
described_class.new(db, 'tyler', docs, options)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'returns false' do
|
74
|
-
expect(message).not_to eq(other)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'when the documents are not equal' do
|
79
|
-
let(:other) do
|
80
|
-
described_class.new(db, collection_name, docs[1..1], options)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'returns false' do
|
84
|
-
expect(message).not_to eq(other)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'when the options are not equal' do
|
89
|
-
let(:other) do
|
90
|
-
described_class.new(db, collection_name, docs, :flags => [:continue_on_error])
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'returns false' do
|
94
|
-
expect(message).not_to eq(other)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'when the other is not an insert' do
|
100
|
-
let(:other) do
|
101
|
-
expect(message).not_to eq('test')
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
describe '#hash' do
|
107
|
-
let(:values) do
|
108
|
-
message.send(:fields).map do |field|
|
109
|
-
message.instance_variable_get(field[:name])
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'returns a hash of the field values' do
|
114
|
-
expect(message.hash).to eq(values.hash)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe '#replyable?' do
|
119
|
-
|
120
|
-
it 'returns false' do
|
121
|
-
expect(message).to_not be_replyable
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe '#serialize' do
|
126
|
-
let(:bytes) { message.serialize }
|
127
|
-
|
128
|
-
include_examples 'message with a header'
|
129
|
-
|
130
|
-
describe 'flags' do
|
131
|
-
let(:field) { bytes.to_s[16..19] }
|
132
|
-
|
133
|
-
context 'when no flags are provided' do
|
134
|
-
it 'does not set any bits' do
|
135
|
-
expect(field).to be_int32(0)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'when flags are provided' do
|
140
|
-
let(:options) { { :flags => flags } }
|
141
|
-
|
142
|
-
context 'continue on error flag' do
|
143
|
-
let(:flags) { [:continue_on_error] }
|
144
|
-
it 'sets the first bit' do
|
145
|
-
expect(field).to be_int32(1)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe 'namespace' do
|
152
|
-
let(:field) { bytes.to_s[20..36] }
|
153
|
-
it 'serializes the namespace' do
|
154
|
-
expect(field).to be_cstring(ns)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe 'documents' do
|
159
|
-
let(:field) { bytes.to_s[37..-1] }
|
160
|
-
it 'serializes the documents' do
|
161
|
-
expect(field).to be_bson_sequence(docs)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe '#registry' do
|
167
|
-
|
168
|
-
context 'when the class is loaded' do
|
169
|
-
|
170
|
-
it 'registers the op code in the Protocol Registry' do
|
171
|
-
expect(Mongo::Protocol::Registry.get(described_class::OP_CODE)).to be(described_class)
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'creates an #op_code instance method' do
|
175
|
-
expect(message.op_code).to eq(described_class::OP_CODE)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|