mongo 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.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +14 -1
  5. data/lib/mongo.rb +2 -1
  6. data/lib/mongo/auth.rb +2 -2
  7. data/lib/mongo/bulk_write.rb +52 -0
  8. data/lib/mongo/bulk_write/bulk_writable.rb +191 -0
  9. data/lib/mongo/bulk_write/deletable.rb +60 -0
  10. data/lib/mongo/bulk_write/insertable.rb +52 -0
  11. data/lib/mongo/bulk_write/ordered_bulk_write.rb +48 -0
  12. data/lib/mongo/bulk_write/replacable.rb +57 -0
  13. data/lib/mongo/bulk_write/unordered_bulk_write.rb +46 -0
  14. data/lib/mongo/bulk_write/updatable.rb +68 -0
  15. data/lib/mongo/client.rb +15 -2
  16. data/lib/mongo/cluster/topology/replica_set.rb +1 -1
  17. data/lib/mongo/cluster/topology/sharded.rb +1 -1
  18. data/lib/mongo/cluster/topology/standalone.rb +1 -1
  19. data/lib/mongo/cluster/topology/unknown.rb +1 -1
  20. data/lib/mongo/collection.rb +1 -1
  21. data/lib/mongo/collection/view/aggregation.rb +1 -1
  22. data/lib/mongo/collection/view/readable.rb +1 -1
  23. data/lib/mongo/collection/view/writable.rb +5 -5
  24. data/lib/mongo/cursor.rb +0 -2
  25. data/lib/mongo/error.rb +4 -3
  26. data/lib/mongo/error/{bulk_write_failure.rb → bulk_write_error.rb} +2 -2
  27. data/lib/mongo/error/invalid_bulk_operation.rb +2 -2
  28. data/lib/mongo/error/invalid_bulk_operation_type.rb +36 -0
  29. data/lib/mongo/error/{empty_batch.rb → multi_index_drop.rb} +5 -10
  30. data/lib/mongo/grid/file/metadata.rb +1 -8
  31. data/lib/mongo/grid/fs.rb +5 -5
  32. data/lib/mongo/index/view.rb +90 -34
  33. data/lib/mongo/operation.rb +0 -1
  34. data/lib/mongo/operation/aggregate.rb +2 -2
  35. data/lib/mongo/operation/aggregate/result.rb +4 -0
  36. data/lib/mongo/operation/bulk_delete/result.rb +2 -127
  37. data/lib/mongo/operation/bulk_insert/result.rb +2 -132
  38. data/lib/mongo/operation/bulk_update/result.rb +2 -142
  39. data/lib/mongo/operation/command.rb +1 -1
  40. data/lib/mongo/operation/executable.rb +3 -3
  41. data/lib/mongo/operation/list_collections/result.rb +0 -2
  42. data/lib/mongo/operation/map_reduce.rb +1 -1
  43. data/lib/mongo/operation/read/collections_info.rb +1 -1
  44. data/lib/mongo/operation/read/get_more.rb +1 -1
  45. data/lib/mongo/operation/read/indexes.rb +1 -1
  46. data/lib/mongo/operation/read/list_collections.rb +1 -1
  47. data/lib/mongo/operation/read/list_indexes.rb +1 -1
  48. data/lib/mongo/operation/read/query.rb +1 -1
  49. data/lib/mongo/operation/specifiable.rb +18 -1
  50. data/lib/mongo/operation/write.rb +2 -0
  51. data/lib/mongo/operation/write/bulk_delete.rb +5 -19
  52. data/lib/mongo/operation/write/bulk_insert.rb +9 -40
  53. data/lib/mongo/operation/write/bulk_mergable.rb +67 -0
  54. data/lib/mongo/operation/write/bulk_update.rb +5 -19
  55. data/lib/mongo/operation/write/command.rb +1 -1
  56. data/lib/mongo/operation/write/command/{ensure_index.rb → create_index.rb} +4 -9
  57. data/lib/mongo/operation/write/command/delete.rb +4 -4
  58. data/lib/mongo/operation/write/command/drop_index.rb +1 -1
  59. data/lib/mongo/operation/write/command/insert.rb +4 -4
  60. data/lib/mongo/operation/write/command/update.rb +4 -4
  61. data/lib/mongo/operation/write/create_index.rb +12 -7
  62. data/lib/mongo/operation/write/create_user.rb +1 -1
  63. data/lib/mongo/operation/write/delete.rb +1 -1
  64. data/lib/mongo/operation/write/drop_index.rb +1 -1
  65. data/lib/mongo/operation/write/insert.rb +1 -1
  66. data/lib/mongo/operation/write/legacy_bulk_mergable.rb +83 -0
  67. data/lib/mongo/operation/write/remove_user.rb +1 -1
  68. data/lib/mongo/operation/write/update.rb +1 -1
  69. data/lib/mongo/{bulk.rb → options.rb} +2 -2
  70. data/lib/mongo/options/mapper.rb +78 -0
  71. data/lib/mongo/server.rb +2 -2
  72. data/lib/mongo/server/connection_pool/queue.rb +1 -1
  73. data/lib/mongo/server/description.rb +1 -1
  74. data/lib/mongo/server/description/inspector.rb +1 -1
  75. data/lib/mongo/server_selector.rb +1 -1
  76. data/lib/mongo/socket/unix.rb +2 -4
  77. data/lib/mongo/version.rb +1 -1
  78. data/lib/mongo/write_concern/acknowledged.rb +15 -1
  79. data/lib/mongo/write_concern/normalizable.rb +0 -22
  80. data/lib/mongo/write_concern/unacknowledged.rb +12 -0
  81. data/spec/mongo/bulk/bulk_write_spec.rb +178 -91
  82. data/spec/mongo/collection/view/aggregation_spec.rb +14 -1
  83. data/spec/mongo/collection/view/explainable_spec.rb +1 -1
  84. data/spec/mongo/collection/view/map_reduce_spec.rb +2 -2
  85. data/spec/mongo/collection/view/readable_spec.rb +2 -2
  86. data/spec/mongo/collection/view/writable_spec.rb +7 -7
  87. data/spec/mongo/collection/view_spec.rb +14 -5
  88. data/spec/mongo/collection_spec.rb +5 -5
  89. data/spec/mongo/cursor_spec.rb +3 -3
  90. data/spec/mongo/database_spec.rb +4 -8
  91. data/spec/mongo/grid/fs_spec.rb +8 -8
  92. data/spec/mongo/index/view_spec.rb +139 -35
  93. data/spec/mongo/operation/aggregate_spec.rb +14 -22
  94. data/spec/mongo/operation/command_spec.rb +8 -16
  95. data/spec/mongo/operation/map_reduce_spec.rb +1 -1
  96. data/spec/mongo/operation/read/indexes_spec.rb +2 -2
  97. data/spec/mongo/operation/write/bulk_delete_spec.rb +1 -239
  98. data/spec/mongo/operation/write/bulk_insert_spec.rb +3 -234
  99. data/spec/mongo/operation/write/bulk_update_spec.rb +1 -289
  100. data/spec/mongo/operation/write/command/delete_spec.rb +0 -13
  101. data/spec/mongo/operation/write/command/insert_spec.rb +0 -14
  102. data/spec/mongo/operation/write/command/update_spec.rb +0 -14
  103. data/spec/mongo/operation/write/{ensure_index_spec.rb → create_index_spec.rb} +8 -26
  104. data/spec/mongo/operation/write/delete_spec.rb +1 -1
  105. data/spec/mongo/operation/write/drop_index_spec.rb +1 -1
  106. data/spec/mongo/operation/write/insert_spec.rb +3 -3
  107. data/spec/mongo/operation/write/update_spec.rb +1 -1
  108. data/spec/mongo/server_selection_spec.rb +2 -2
  109. data/spec/support/authorization.rb +4 -2
  110. data/spec/support/server_selection.rb +25 -8
  111. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +4 -10
  112. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +6 -12
  113. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +4 -6
  114. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +4 -10
  115. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +6 -12
  116. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +4 -10
  117. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +4 -10
  118. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +6 -12
  119. data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +6 -12
  120. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +9 -17
  121. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +9 -17
  122. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +6 -10
  123. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +11 -21
  124. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +11 -18
  125. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary.yml +31 -0
  126. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred.yml +31 -0
  127. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_non_matching.yml +29 -0
  128. data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Secondary_non_matching.yml +26 -0
  129. data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +4 -10
  130. data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +2 -6
  131. data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +0 -2
  132. data/spec/support/shared/bulk_write.rb +109 -72
  133. metadata +29 -10
  134. metadata.gz.sig +0 -0
  135. data/lib/mongo/bulk/bulk_write.rb +0 -307
  136. data/lib/mongo/operation/batchable.rb +0 -103
@@ -61,7 +61,7 @@ describe Mongo::Collection::View::Aggregation do
61
61
  end
62
62
 
63
63
  after do
64
- authorized_collection.find.remove_many
64
+ authorized_collection.find.delete_many
65
65
  end
66
66
 
67
67
  context 'when a block is provided' do
@@ -108,6 +108,19 @@ describe Mongo::Collection::View::Aggregation do
108
108
  expect(aggregation.each).to be_a(Enumerator)
109
109
  end
110
110
  end
111
+
112
+ context 'when an invalid pipeline operator is provided' do
113
+
114
+ let(:pipeline) do
115
+ [{ '$invalid' => 'operator' }]
116
+ end
117
+
118
+ it 'raises an OperationFailure' do
119
+ expect {
120
+ aggregation.to_a
121
+ }.to raise_error(Mongo::Error::OperationFailure)
122
+ end
123
+ end
111
124
  end
112
125
 
113
126
  describe '#initialize' do
@@ -15,7 +15,7 @@ describe Mongo::Collection::View::Explainable do
15
15
  end
16
16
 
17
17
  after do
18
- authorized_collection.find.remove_many
18
+ authorized_collection.find.delete_many
19
19
  end
20
20
 
21
21
  describe '#explain' do
@@ -48,7 +48,7 @@ describe Mongo::Collection::View::MapReduce do
48
48
  end
49
49
 
50
50
  after do
51
- authorized_collection.find.remove_many
51
+ authorized_collection.find.delete_many
52
52
  end
53
53
 
54
54
  let(:map_reduce) do
@@ -82,7 +82,7 @@ describe Mongo::Collection::View::MapReduce do
82
82
  context 'when out is a collection' do
83
83
 
84
84
  after do
85
- authorized_client['output_collection'].find.remove_many
85
+ authorized_client['output_collection'].find.delete_many
86
86
  end
87
87
 
88
88
  context 'when the option is to replace' do
@@ -15,7 +15,7 @@ describe Mongo::Collection::View::Readable do
15
15
  end
16
16
 
17
17
  after do
18
- authorized_collection.find.remove_many
18
+ authorized_collection.find.delete_many
19
19
  end
20
20
 
21
21
  describe '#allow_partial_results' do
@@ -200,7 +200,7 @@ describe Mongo::Collection::View::Readable do
200
200
  end
201
201
 
202
202
  after do
203
- authorized_collection.find.remove_many
203
+ authorized_collection.find.delete_many
204
204
  end
205
205
 
206
206
  context 'when a selector is provided' do
@@ -15,7 +15,7 @@ describe Mongo::Collection::View::Writable do
15
15
  end
16
16
 
17
17
  after do
18
- authorized_collection.find.remove_many
18
+ authorized_collection.find.delete_many
19
19
  end
20
20
 
21
21
  describe '#find_one_and_delete' do
@@ -263,7 +263,7 @@ describe Mongo::Collection::View::Writable do
263
263
  end
264
264
  end
265
265
 
266
- describe '#remove_many' do
266
+ describe '#delete_many' do
267
267
 
268
268
  context 'when a selector was provided' do
269
269
 
@@ -276,7 +276,7 @@ describe Mongo::Collection::View::Writable do
276
276
  end
277
277
 
278
278
  let(:response) do
279
- view.remove_many
279
+ view.delete_many
280
280
  end
281
281
 
282
282
  it 'deletes the matching documents in the collection' do
@@ -291,7 +291,7 @@ describe Mongo::Collection::View::Writable do
291
291
  end
292
292
 
293
293
  let(:response) do
294
- view.remove_many
294
+ view.delete_many
295
295
  end
296
296
 
297
297
  it 'deletes all the documents in the collection' do
@@ -300,7 +300,7 @@ describe Mongo::Collection::View::Writable do
300
300
  end
301
301
  end
302
302
 
303
- describe '#remove_one' do
303
+ describe '#delete_one' do
304
304
 
305
305
  context 'when a selector was provided' do
306
306
 
@@ -317,7 +317,7 @@ describe Mongo::Collection::View::Writable do
317
317
  end
318
318
 
319
319
  let(:response) do
320
- view.remove_one
320
+ view.delete_one
321
321
  end
322
322
 
323
323
  it 'deletes the first matching document in the collection' do
@@ -332,7 +332,7 @@ describe Mongo::Collection::View::Writable do
332
332
  end
333
333
 
334
334
  let(:response) do
335
- view.remove_one
335
+ view.delete_one
336
336
  end
337
337
 
338
338
  it 'deletes the first document in the collection' do
@@ -15,7 +15,7 @@ describe Mongo::Collection::View do
15
15
  end
16
16
 
17
17
  after do
18
- authorized_collection.find.remove_many
18
+ authorized_collection.find.delete_many
19
19
  end
20
20
 
21
21
  describe '#==' do
@@ -116,7 +116,7 @@ describe Mongo::Collection::View do
116
116
  end
117
117
 
118
118
  after do
119
- authorized_collection.find.remove_many
119
+ authorized_collection.find.delete_many
120
120
  end
121
121
 
122
122
  context 'when sending the initial query' do
@@ -401,9 +401,18 @@ describe Mongo::Collection::View do
401
401
  end
402
402
  end
403
403
 
404
- pending 'when the cursor is created'
405
- pending 'when a block is provided'
406
- pending 'when a block is not provided'
404
+ context 'when a block is not provided' do
405
+
406
+ let(:enumerator) do
407
+ view.each
408
+ end
409
+
410
+ it 'returns an enumerator' do
411
+ enumerator.each do |doc|
412
+ expect(doc).to have_key('field')
413
+ end
414
+ end
415
+ end
407
416
  end
408
417
 
409
418
  describe '#hash' do
@@ -262,7 +262,7 @@ describe Mongo::Collection do
262
262
  end
263
263
 
264
264
  after do
265
- authorized_collection.find.remove_many
265
+ authorized_collection.find.delete_many
266
266
  end
267
267
 
268
268
  let(:view) do
@@ -280,7 +280,7 @@ describe Mongo::Collection do
280
280
  describe '#insert_many' do
281
281
 
282
282
  after do
283
- authorized_collection.find.remove_many
283
+ authorized_collection.find.delete_many
284
284
  end
285
285
 
286
286
  let(:result) do
@@ -299,7 +299,7 @@ describe Mongo::Collection do
299
299
  describe '#insert_one' do
300
300
 
301
301
  after do
302
- authorized_collection.find.remove_many
302
+ authorized_collection.find.delete_many
303
303
  end
304
304
 
305
305
  let(:result) do
@@ -339,11 +339,11 @@ describe Mongo::Collection do
339
339
  end
340
340
 
341
341
  before do
342
- authorized_collection.indexes.create(index_spec, unique: true)
342
+ authorized_collection.indexes.create_one(index_spec, unique: true)
343
343
  end
344
344
 
345
345
  after do
346
- authorized_collection.indexes.drop(index_spec)
346
+ authorized_collection.indexes.drop_one('name_1')
347
347
  end
348
348
 
349
349
  it 'returns a list of indexes' do
@@ -33,7 +33,7 @@ describe Mongo::Cursor do
33
33
  end
34
34
 
35
35
  after do
36
- authorized_collection.find.remove_many
36
+ authorized_collection.find.delete_many
37
37
  end
38
38
 
39
39
  it 'returns the correct amount' do
@@ -58,7 +58,7 @@ describe Mongo::Cursor do
58
58
  end
59
59
 
60
60
  after do
61
- authorized_collection.find.remove_many
61
+ authorized_collection.find.delete_many
62
62
  end
63
63
 
64
64
  it 'returns the correct amount' do
@@ -84,7 +84,7 @@ describe Mongo::Cursor do
84
84
  end
85
85
 
86
86
  after do
87
- authorized_collection.find.remove_many
87
+ authorized_collection.find.delete_many
88
88
  end
89
89
 
90
90
  context 'when a limit is provided' do
@@ -126,11 +126,9 @@ describe Mongo::Database do
126
126
  described_class.new(authorized_client, 'invalid_database')
127
127
  end
128
128
 
129
- it 'returns an empty list', if: list_command_enabled? do
129
+ it 'returns an empty list', if: write_command_enabled? do
130
130
  expect(database.collections).to be_empty
131
131
  end
132
-
133
- pending 'raises an exception' # 2.6
134
132
  end
135
133
 
136
134
  context 'when the user is not authorized', unless: sharded? do
@@ -139,13 +137,11 @@ describe Mongo::Database do
139
137
  described_class.new(unauthorized_client, TEST_DB)
140
138
  end
141
139
 
142
- it 'raises an exception', if: list_command_enabled? do
140
+ it 'raises an exception' do
143
141
  expect {
144
142
  database.collections
145
143
  }.to raise_error(Mongo::Error::OperationFailure)
146
144
  end
147
-
148
- pending 'raises an exception' # 2.6 not authorized
149
145
  end
150
146
  end
151
147
 
@@ -267,8 +263,8 @@ describe Mongo::Database do
267
263
  end
268
264
 
269
265
  after do
270
- fs.files_collection.find.remove_many
271
- fs.chunks_collection.find.remove_many
266
+ fs.files_collection.find.delete_many
267
+ fs.chunks_collection.find.delete_many
272
268
  end
273
269
 
274
270
  let(:from_db) do
@@ -40,8 +40,8 @@ describe Mongo::Grid::FS do
40
40
  end
41
41
 
42
42
  after do
43
- fs.files_collection.find.remove_many
44
- fs.chunks_collection.find.remove_many
43
+ fs.files_collection.find.delete_many
44
+ fs.chunks_collection.find.delete_many
45
45
  end
46
46
 
47
47
  let(:from_db) do
@@ -70,8 +70,8 @@ describe Mongo::Grid::FS do
70
70
  end
71
71
 
72
72
  after do
73
- fs.files_collection.find.remove_many
74
- fs.chunks_collection.find.remove_many
73
+ fs.files_collection.find.delete_many
74
+ fs.chunks_collection.find.delete_many
75
75
  end
76
76
 
77
77
  let(:from_db) do
@@ -90,8 +90,8 @@ describe Mongo::Grid::FS do
90
90
  context 'when inserting the file more than once' do
91
91
 
92
92
  after do
93
- fs.files_collection.find.remove_many
94
- fs.chunks_collection.find.remove_many
93
+ fs.files_collection.find.delete_many
94
+ fs.chunks_collection.find.delete_many
95
95
  end
96
96
 
97
97
  it 'raises an error' do
@@ -103,7 +103,7 @@ describe Mongo::Grid::FS do
103
103
  end
104
104
  end
105
105
 
106
- describe '#remove_one' do
106
+ describe '#delete_one' do
107
107
 
108
108
  let(:fs) do
109
109
  described_class.new(authorized_client.database)
@@ -115,7 +115,7 @@ describe Mongo::Grid::FS do
115
115
 
116
116
  before do
117
117
  fs.insert_one(file)
118
- fs.remove_one(file)
118
+ fs.delete_one(file)
119
119
  end
120
120
 
121
121
  let(:from_db) do
@@ -6,41 +6,33 @@ describe Mongo::Index::View do
6
6
  described_class.new(authorized_collection)
7
7
  end
8
8
 
9
- describe '#drop' do
9
+ describe '#drop_one' do
10
10
 
11
11
  let(:spec) do
12
12
  { another: -1 }
13
13
  end
14
14
 
15
15
  before do
16
- view.create(spec, unique: true)
16
+ view.create_one(spec, unique: true)
17
17
  end
18
18
 
19
- context 'when providing an index spec' do
19
+ context 'when the index exists' do
20
20
 
21
- context 'when the index exists' do
22
-
23
- let(:result) do
24
- view.drop(spec)
25
- end
21
+ let(:result) do
22
+ view.drop_one('another_-1')
23
+ end
26
24
 
27
- it 'drops the index' do
28
- expect(result).to be_successful
29
- end
25
+ it 'drops the index' do
26
+ expect(result).to be_successful
30
27
  end
31
28
  end
32
29
 
33
- context 'when providing an index name' do
34
-
35
- context 'when the index exists' do
36
-
37
- let(:result) do
38
- view.drop('another_-1')
39
- end
30
+ context 'when passing a * as the name' do
40
31
 
41
- it 'drops the index' do
42
- expect(result).to be_successful
43
- end
32
+ it 'raises an exception' do
33
+ expect {
34
+ view.drop_one('*')
35
+ }.to raise_error(Mongo::Error::MultiIndexDrop)
44
36
  end
45
37
  end
46
38
  end
@@ -52,7 +44,7 @@ describe Mongo::Index::View do
52
44
  end
53
45
 
54
46
  before do
55
- view.create(spec, unique: true)
47
+ view.create_one(spec, unique: true)
56
48
  end
57
49
 
58
50
  context 'when indexes exists' do
@@ -67,7 +59,76 @@ describe Mongo::Index::View do
67
59
  end
68
60
  end
69
61
 
70
- describe '#create' do
62
+ describe '#create_many' do
63
+
64
+ context 'when the indexes are created' do
65
+
66
+ context 'when passing multi-args' do
67
+
68
+ let(:result) do
69
+ view.create_many(
70
+ { key: { random: 1 }, unique: true },
71
+ { key: { testing: -1 }, unique: true }
72
+ )
73
+ end
74
+
75
+ after do
76
+ view.drop_one('random_1')
77
+ view.drop_one('testing_-1')
78
+ end
79
+
80
+ it 'returns ok' do
81
+ expect(result).to be_successful
82
+ end
83
+ end
84
+
85
+ context 'when passing an array' do
86
+
87
+ let(:result) do
88
+ view.create_many([
89
+ { key: { random: 1 }, unique: true },
90
+ { key: { testing: -1 }, unique: true }
91
+ ])
92
+ end
93
+
94
+ after do
95
+ view.drop_one('random_1')
96
+ view.drop_one('testing_-1')
97
+ end
98
+
99
+ it 'returns ok' do
100
+ expect(result).to be_successful
101
+ end
102
+ end
103
+
104
+ context 'when index creation fails' do
105
+
106
+ let(:spec) do
107
+ { name: 1 }
108
+ end
109
+
110
+ before do
111
+ view.create_one(spec, unique: true)
112
+ end
113
+
114
+ after do
115
+ view.drop_one('name_1')
116
+ end
117
+
118
+ it 'raises an exception', if: write_command_enabled? do
119
+ expect {
120
+ view.create_many([{ key: { name: 1 }, unique: false }])
121
+ }.to raise_error(Mongo::Error::OperationFailure)
122
+ end
123
+
124
+ it 'does not raise an exception', unless: write_command_enabled? do
125
+ expect(view.create_many([{ key: { name: 1 }, unique: false }])).to be_successful
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ describe '#create_one' do
71
132
 
72
133
  context 'when the index is created' do
73
134
 
@@ -76,11 +137,11 @@ describe Mongo::Index::View do
76
137
  end
77
138
 
78
139
  let(:result) do
79
- view.create(spec, unique: true)
140
+ view.create_one(spec, unique: true)
80
141
  end
81
142
 
82
143
  after do
83
- view.drop(spec)
144
+ view.drop_one('random_1')
84
145
  end
85
146
 
86
147
  it 'returns ok' do
@@ -95,21 +156,21 @@ describe Mongo::Index::View do
95
156
  end
96
157
 
97
158
  before do
98
- view.create(spec, unique: true)
159
+ view.create_one(spec, unique: true)
99
160
  end
100
161
 
101
162
  after do
102
- view.drop(spec)
163
+ view.drop_one('name_1')
103
164
  end
104
165
 
105
166
  it 'raises an exception', if: write_command_enabled? do
106
167
  expect {
107
- view.create(spec, unique: false)
168
+ view.create_one(spec, unique: false)
108
169
  }.to raise_error(Mongo::Error::OperationFailure)
109
170
  end
110
171
 
111
172
  it 'does not raise an exception', unless: write_command_enabled? do
112
- expect(view.create(spec, unique: false)).to be_successful
173
+ expect(view.create_one(spec, unique: false)).to be_successful
113
174
  end
114
175
  end
115
176
 
@@ -120,11 +181,11 @@ describe Mongo::Index::View do
120
181
  end
121
182
 
122
183
  let!(:result) do
123
- view.create(spec, unique: true, name: 'random_name')
184
+ view.create_one(spec, unique: true, name: 'random_name')
124
185
  end
125
186
 
126
187
  after do
127
- view.drop('random_name')
188
+ view.drop_one('random_name')
128
189
  end
129
190
 
130
191
  it 'returns ok' do
@@ -144,11 +205,11 @@ describe Mongo::Index::View do
144
205
  end
145
206
 
146
207
  let!(:result) do
147
- view.create(spec, unique: true, name: 'random_name')
208
+ view.create_one(spec, unique: true, name: 'random_name')
148
209
  end
149
210
 
150
211
  after do
151
- view.drop('random_name')
212
+ view.drop_one('random_name')
152
213
  end
153
214
 
154
215
  context 'when providing a name' do
@@ -190,11 +251,11 @@ describe Mongo::Index::View do
190
251
  end
191
252
 
192
253
  before do
193
- view.create(spec, unique: true)
254
+ view.create_one(spec, unique: true)
194
255
  end
195
256
 
196
257
  after do
197
- view.drop(spec)
258
+ view.drop_one('name_1')
198
259
  end
199
260
 
200
261
  let(:indexes) do
@@ -223,4 +284,47 @@ describe Mongo::Index::View do
223
284
  end
224
285
  end
225
286
  end
287
+
288
+ describe '#normalize_models' do
289
+
290
+ context 'when providing options' do
291
+
292
+ let(:options) do
293
+ {
294
+ :key => { :name => 1 },
295
+ :bucket_size => 5,
296
+ :default_language => 'deutsch',
297
+ :expire_after => 10,
298
+ :language_override => 'language',
299
+ :sphere_version => 1,
300
+ :storage_engine => 'wiredtiger',
301
+ :text_version => 2,
302
+ :version => 1
303
+ }
304
+ end
305
+
306
+ let(:models) do
307
+ view.send(:normalize_models, [ options ])
308
+ end
309
+
310
+ let(:expected) do
311
+ {
312
+ :key => { :name => 1 },
313
+ :name => 'name_1',
314
+ :bucketSize => 5,
315
+ :default_language => 'deutsch',
316
+ :expireAfterSeconds => 10,
317
+ :language_override => 'language',
318
+ :'2dsphereIndexVersion' => 1,
319
+ :storageEngine => 'wiredtiger',
320
+ :textIndexVersion => 2,
321
+ :v => 1
322
+ }
323
+ end
324
+
325
+ it 'maps the ruby options to the server options' do
326
+ expect(models).to eq([ expected ])
327
+ end
328
+ end
329
+ end
226
330
  end