find -> findOne

This commit is contained in:
James Allen 2016-03-08 14:19:38 +00:00
parent 0882eb2a99
commit 359689ffea
2 changed files with 16 additions and 16 deletions

View file

@ -37,7 +37,7 @@ module.exports = ReferencesHandler =
callback(null, owner?.features?.references == true)
indexAll: (projectId, callback=(err, data)->) ->
Project.find { _id: projectId }, (err, project) ->
Project.findOne { _id: projectId }, (err, project) ->
if err
logger.err {err, projectId}, "error finding project"
return callback(err)
@ -46,7 +46,7 @@ module.exports = ReferencesHandler =
ReferencesHandler._doIndexOperation(projectId, project, docIds, callback)
index: (projectId, docIds, callback=(err, data)->) ->
Project.find { _id: projectId }, (err, project) ->
Project.findOne { _id: projectId }, (err, project) ->
if err
logger.err {err, projectId}, "error finding project"
return callback(err)

View file

@ -41,7 +41,7 @@ describe 'ReferencesHandler', ->
}
'../../models/Project': {
Project: @Project = {
find: sinon.stub().callsArgWith(1, null, @fakeProject)
findOne: sinon.stub().callsArgWith(1, null, @fakeProject)
}
}
'../../models/User': {
@ -73,10 +73,10 @@ describe 'ReferencesHandler', ->
@handler._findBibDocIds.callCount.should.equal 0
done()
it 'should call Project.find', (done) ->
it 'should call Project.findOne', (done) ->
@call (err, data) =>
@Project.find.callCount.should.equal 1
@Project.find.calledWith(_id: @projectId).should.equal true
@Project.findOne.callCount.should.equal 1
@Project.findOne.calledWith(_id: @projectId).should.equal true
done()
it 'should not call _findBibDocIds', (done) ->
@ -112,10 +112,10 @@ describe 'ReferencesHandler', ->
expect(data).to.equal @fakeResponseData
done()
describe 'when Project.find produces an error', ->
describe 'when Project.findOne produces an error', ->
beforeEach ->
@Project.find.callsArgWith(1, new Error('woops'))
@Project.findOne.callsArgWith(1, new Error('woops'))
it 'should produce an error', (done) ->
@call (err, data) =>
@ -132,7 +132,7 @@ describe 'ReferencesHandler', ->
describe 'when _isFullIndex produces an error', ->
beforeEach ->
@Project.find.callsArgWith(1, null, @fakeProject)
@Project.findOne.callsArgWith(1, null, @fakeProject)
@handler._isFullIndex.callsArgWith(1, new Error('woops'))
it 'should produce an error', (done) ->
@ -150,7 +150,7 @@ describe 'ReferencesHandler', ->
describe 'when flushDocToMongo produces an error', ->
beforeEach ->
@Project.find.callsArgWith(1, null, @fakeProject)
@Project.findOne.callsArgWith(1, null, @fakeProject)
@handler._isFullIndex.callsArgWith(1, false)
@DocumentUpdaterHandler.flushDocToMongo.callsArgWith(2, new Error('woops'))
@ -170,7 +170,7 @@ describe 'ReferencesHandler', ->
describe 'when request produces an error', ->
beforeEach ->
@Project.find.callsArgWith(1, null, @fakeProject)
@Project.findOne.callsArgWith(1, null, @fakeProject)
@handler._isFullIndex.callsArgWith(1, null, false)
@DocumentUpdaterHandler.flushDocToMongo.callsArgWith(2, null)
@request.post.callsArgWith(1, new Error('woops'))
@ -185,7 +185,7 @@ describe 'ReferencesHandler', ->
describe 'when request responds with error status', ->
beforeEach ->
@Project.find.callsArgWith(1, null, @fakeProject)
@Project.findOne.callsArgWith(1, null, @fakeProject)
@handler._isFullIndex.callsArgWith(1, null, false)
@request.post.callsArgWith(1, null, {statusCode: 500}, null)
@ -237,10 +237,10 @@ describe 'ReferencesHandler', ->
expect(data).to.equal @fakeResponseData
done()
describe 'when Project.find produces an error', ->
describe 'when Project.findOne produces an error', ->
beforeEach ->
@Project.find.callsArgWith(1, new Error('woops'))
@Project.findOne.callsArgWith(1, new Error('woops'))
it 'should produce an error', (done) ->
@call (err, data) =>
@ -257,7 +257,7 @@ describe 'ReferencesHandler', ->
describe 'when _isFullIndex produces an error', ->
beforeEach ->
@Project.find.callsArgWith(1, null, @fakeProject)
@Project.findOne.callsArgWith(1, null, @fakeProject)
@handler._isFullIndex.callsArgWith(1, new Error('woops'))
it 'should produce an error', (done) ->
@ -275,7 +275,7 @@ describe 'ReferencesHandler', ->
describe 'when flushDocToMongo produces an error', ->
beforeEach ->
@Project.find.callsArgWith(1, null, @fakeProject)
@Project.findOne.callsArgWith(1, null, @fakeProject)
@handler._isFullIndex.callsArgWith(1, false)
@DocumentUpdaterHandler.flushDocToMongo.callsArgWith(2, new Error('woops'))