Don't return deleted docs by default, make it a flag

This commit is contained in:
James Allen 2014-06-06 12:37:42 +01:00
parent 4818ae8131
commit 6d24c69e96
4 changed files with 62 additions and 19 deletions

View file

@ -5,8 +5,9 @@ module.exports = HttpController =
getDoc: (req, res, next = (error) ->) ->
project_id = req.params.project_id
doc_id = req.params.doc_id
include_deleted = req.query?.include_deleted == "true"
logger.log project_id: project_id, doc_id: doc_id, "getting doc"
DocManager.getDoc project_id, doc_id, include_deleted: true, (error, doc) ->
DocManager.getDoc project_id, doc_id, include_deleted: include_deleted, (error, doc) ->
return next(error) if error?
logger.log doc: doc, "got doc"
if !doc?

View file

@ -32,3 +32,21 @@ describe "Getting a doc", ->
res.statusCode.should.equal 404
done()
describe "when the doc is a deleted doc", ->
beforeEach (done) ->
@deleted_doc_id = ObjectId()
DocstoreClient.createDeletedDoc @project_id, @deleted_doc_id, @lines, done
describe "with include_deleted=true", ->
it "should return the doc", (done) ->
DocstoreClient.getDoc @project_id, @deleted_doc_id, include_deleted: true, (error, res, doc) =>
doc.lines.should.deep.equal @lines
doc.deleted.should.equal true
done()
describe "without include_deleted=true", ->
it "should return 404", (done) ->
DocstoreClient.getDoc @project_id, @deleted_doc_id, (error, res, doc) =>
res.statusCode.should.equal 404
done()

View file

@ -20,12 +20,23 @@ module.exports = DocstoreClient =
}
}, callback
createDeletedDoc: (project_id, doc_id, lines, callback = (error) ->) ->
db.docs.insert {
_id: doc_id
project_id: project_id
lines: lines
deleted: true
}, callback
deleteProject: (project_id, callback = (error, res, body) ->) ->
db.projects.remove _id: project_id, callback
getDoc: (project_id, doc_id, callback = (error, res, body) ->) ->
getDoc: (project_id, doc_id, options, callback = (error, res, body) ->) ->
if typeof(options) == "function"
callback = options
options = { include_deleted: false }
request.get {
url: "http://localhost:3016/project/#{project_id}/doc/#{doc_id}"
url: "http://localhost:3016/project/#{project_id}/doc/#{doc_id}?include_deleted=#{options.include_deleted}"
json: true
}, callback
@ -45,8 +56,7 @@ module.exports = DocstoreClient =
deleteDoc: (project_id, doc_id, callback = (error, res, body) ->) ->
request.del {
url: "http://localhost:3016/project/#{project_id}/doc/#{doc_id}"
}, callback
}, callback

View file

@ -30,22 +30,36 @@ describe "HttpController", ->
project_id: @project_id
doc_id: @doc_id
@DocManager.getDoc = sinon.stub().callsArgWith(3, null, @doc)
@HttpController.getDoc @req, @res, @next
it "should get the document (including deleted)", ->
@DocManager.getDoc
.calledWith(@project_id, @doc_id, include_deleted: true)
.should.equal true
describe "without deleted docs", ->
beforeEach ->
@HttpController.getDoc @req, @res, @next
it "should return the doc as JSON", ->
@res.json
.calledWith({
_id: @doc_id
lines: @doc.lines
rev: @doc.rev
deleted: false
})
.should.equal true
it "should get the document (including deleted)", ->
@DocManager.getDoc
.calledWith(@project_id, @doc_id, include_deleted: false)
.should.equal true
it "should return the doc as JSON", ->
@res.json
.calledWith({
_id: @doc_id
lines: @doc.lines
rev: @doc.rev
deleted: false
})
.should.equal true
describe "with deleted docs", ->
beforeEach ->
@req.query =
include_deleted: 'true'
@HttpController.getDoc @req, @res, @next
it "should get the document (without deleted)", ->
@DocManager.getDoc
.calledWith(@project_id, @doc_id, include_deleted: true)
.should.equal true
describe "getRawDoc", ->
beforeEach ->