spec/mongo/operation/write/delete_spec.rb in mongo-2.2.7 vs spec/mongo/operation/write/delete_spec.rb in mongo-2.3.0
- old
+ new
@@ -1,26 +1,25 @@
require 'spec_helper'
describe Mongo::Operation::Write::Delete do
- include_context 'operation'
- let(:document) { { :q => { :foo => 1 }, :limit => 1 } }
+ let(:document) do
+ {
+ :q => { :foo => 1 },
+ :limit => 1
+ }
+ end
+
let(:spec) do
{ :delete => document,
- :db_name => db_name,
- :coll_name => coll_name,
- :write_concern => write_concern,
+ :db_name => TEST_DB,
+ :coll_name => TEST_COLL,
+ :write_concern => Mongo::WriteConcern.get(WRITE_CONCERN),
:ordered => true
}
end
- let(:delete_write_cmd) do
- double('delete_write_cmd').tap do |d|
- allow(d).to receive(:execute) { [] }
- end
- end
-
let(:op) { described_class.new(spec) }
describe '#initialize' do
context 'spec' do
@@ -43,15 +42,16 @@
end
end
context 'when two ops have different specs' do
let(:other_doc) { { :q => { :bar => 1 }, :limit => 1 } }
+
let(:other_spec) do
{ :delete => other_doc,
- :db_name => db_name,
- :coll_name => coll_name,
- :write_concern => write_concern,
+ :db_name => TEST_DB,
+ :coll_name => TEST_COLL,
+ :write_concern => Mongo::WriteConcern.get(WRITE_CONCERN),
:ordered => true
}
end
let(:other) { described_class.new(other_spec) }
@@ -80,22 +80,22 @@
let(:delete) do
described_class.new({
delete: document,
db_name: TEST_DB,
coll_name: TEST_COLL,
- write_concern: Mongo::WriteConcern.get(:w => 1)
+ write_concern: Mongo::WriteConcern.get(WRITE_CONCERN)
})
end
context 'when the delete succeeds' do
let(:document) do
{ 'q' => { field: 'test' }, 'limit' => 1 }
end
let(:result) do
- delete.execute(authorized_primary.context)
+ delete.execute(authorized_primary)
end
it 'deletes the documents from the database' do
expect(result.written_count).to eq(1)
end
@@ -111,11 +111,11 @@
{ que: { field: 'test' } }
end
it 'raises an exception' do
expect {
- delete.execute(authorized_primary.context)
+ delete.execute(authorized_primary)
}.to raise_error(Mongo::Error::OperationFailure)
end
end
end
@@ -124,22 +124,22 @@
let(:delete) do
described_class.new({
delete: document,
db_name: TEST_DB,
coll_name: TEST_COLL,
- write_concern: Mongo::WriteConcern.get(:w => 1)
+ write_concern: Mongo::WriteConcern.get(WRITE_CONCERN)
})
end
context 'when the deletes succeed' do
let(:document) do
{ 'q' => { field: 'test' }, 'limit' => 0 }
end
let(:result) do
- delete.execute(authorized_primary.context)
+ delete.execute(authorized_primary)
end
it 'deletes the documents from the database' do
expect(result.written_count).to eq(2)
end
@@ -154,17 +154,17 @@
let(:document) do
failing_delete_doc
end
let(:result) do
- delete.execute(authorized_primary.context)
+ delete.execute(authorized_primary)
end
it 'does not delete any documents' do
expect {
- op.execute(authorized_primary.context)
+ op.execute(authorized_primary)
}.to raise_error(Mongo::Error::OperationFailure)
expect(authorized_collection.find.count).to eq(2)
end
end
@@ -175,12 +175,41 @@
{ 'q' => { field: 't'*17000000 }, 'limit' => 0 }
end
it 'raises an error' do
expect {
- op.execute(authorized_primary.context)
+ op.execute(authorized_primary)
}.to raise_error(Mongo::Error::MaxBSONSize)
end
+ end
+ end
+
+ context 'when write concern { w: 0 } is used' do
+
+ let(:delete) do
+ described_class.new({
+ delete: document,
+ db_name: TEST_DB,
+ coll_name: TEST_COLL,
+ write_concern: Mongo::WriteConcern.get(:w => 0)
+ })
+ end
+
+
+ let(:document) do
+ { 'q' => { field: 'test' }, 'limit' => 1 }
+ end
+
+ let(:result) do
+ delete.execute(authorized_primary)
+ end
+
+ before do
+ expect(delete).to receive(:execute_message).and_call_original
+ end
+
+ it 'uses op codes instead of write commands' do
+ expect(result.written_count).to eq(0)
end
end
end
end