Skip to content

RUBY-907 writeConcernError is a document #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/mongo/error/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def parse!
parse_single(@message, ERROR)
parse_single(@message, ERRMSG)
parse_multiple(@message, WRITE_ERRORS)
parse_multiple(@message, WRITE_CONCERN_ERROR)
parse_single(@message, ERRMSG,
document[WRITE_CONCERN_ERROR]) if document[WRITE_CONCERN_ERROR]
end

def parse_single(message, key, doc = document)
Expand Down
31 changes: 5 additions & 26 deletions spec/mongo/error/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,14 @@
end
end

context 'when the document contains writeConcernErrors' do
context 'when the document contains a writeConcernError' do

context 'when a single error exists' do

let(:document) do
{ 'writeConcernError' => [{ 'errmsg' => 'not authorized for query', 'code' => 13 }]}
end

it 'returns the message' do
expect(parser.message).to eq('not authorized for query (13)')
end
let(:document) do
{ 'writeConcernError' => { 'code' => 100, 'errmsg' => 'Not enough data-bearing nodes' } }
end

context 'when multiple errors exist' do

let(:document) do
{
'writeConcernError' => [
{ 'code' => 9, 'errmsg' => 'Unknown modifier: $st' },
{ 'code' => 9, 'errmsg' => 'Unknown modifier: $bl' }
]
}
end

it 'returns the messages concatenated' do
expect(parser.message).to eq(
'Unknown modifier: $st (9), Unknown modifier: $bl (9)'
)
end
it 'returns the message' do
expect(parser.message).to eq('Not enough data-bearing nodes (100)')
end
end
end
Expand Down