spec/mongo/operation/write/command/insert_spec.rb in mongo-2.2.7 vs spec/mongo/operation/write/command/insert_spec.rb in mongo-2.3.0
- old
+ new
@@ -1,20 +1,23 @@
require 'spec_helper'
describe Mongo::Operation::Write::Command::Insert do
- include_context 'operation'
let(:documents) { [{ :_id => 1, :foo => 1 }] }
let(:spec) do
{ :documents => documents,
- :db_name => db_name,
- :coll_name => coll_name,
+ :db_name => authorized_collection.database.name,
+ :coll_name => authorized_collection.name,
:write_concern => write_concern,
:ordered => true
}
end
+ let(:write_concern) do
+ Mongo::WriteConcern.get(WRITE_CONCERN)
+ end
+
let(:op) { described_class.new(spec) }
describe '#initialize' do
context 'spec' do
@@ -39,12 +42,12 @@
context 'when two ops have different specs' do
let(:other_documents) { [{ :bar => 1 }] }
let(:other_spec) do
{ :documents => other_documents,
- :db_name => db_name,
- :insert => coll_name,
+ :db_name => authorized_collection.database.name,
+ :insert => authorized_collection.name,
:write_concern => write_concern.options,
:ordered => true
}
end
let(:other) { described_class.new(other_spec) }
@@ -60,12 +63,12 @@
context 'when write concern is not specified' do
let(:spec) do
{ :documents => documents,
- :db_name => db_name,
- :coll_name => coll_name,
+ :db_name => authorized_collection.database.name,
+ :coll_name => authorized_collection.name,
:ordered => true
}
end
it 'does not include write concern in the selector' do
@@ -79,34 +82,24 @@
expect(op.send(:selector)[:writeConcern]).to eq(write_concern.options)
end
end
end
- describe '#execute' do
+ describe '#message' do
- context 'server' do
+ let(:expected_selector) do
+ { :documents => documents,
+ :insert => authorized_collection.name,
+ :writeConcern => write_concern.options,
+ :ordered => true
+ }
+ end
- context 'message' do
- let(:expected_selector) do
- { :documents => documents,
- :insert => coll_name,
- :writeConcern => write_concern.options,
- :ordered => true
- }
- end
-
- it 'creates a query wire protocol message with correct specs' do
- allow_any_instance_of(Mongo::ServerSelector::Primary).to receive(:server) do
- primary_server
- end
-
- expect(Mongo::Protocol::Query).to receive(:new) do |db, coll, sel, options|
- expect(db).to eq(db_name)
- expect(coll).to eq(Mongo::Database::COMMAND)
- expect(sel).to eq(expected_selector)
- end
- op.execute(primary_context)
- end
- end
+ it 'creates a query wire protocol message with correct specs' do
+ expect(Mongo::Protocol::Query).to receive(:new).with(authorized_collection.database.name,
+ '$cmd',
+ expected_selector,
+ { limit: -1, validating_keys: true })
+ op.send(:message)
end
end
end