       .end (err, res) ->
         throw err if err
         assert.equal res.body.documents.length, 20
-        for doc in res.body.documents
+        for doc in res.body.documents when doc.status isnt 'Slettet'
+          count++
           do (doc) ->
             req.get('/turer/' + doc._id + '?api_key=dnt')
               .expect(200)
               .end (err, r) ->
                 throw err if err
                 assert.equal r.body.tags[0], 'Sted'
-                done() if ++count is res.body.documents.length
+                done() if --count is 0
 
 describe 'POST', ->
   it 'should insert single object in collection and return ObjectID', (done) ->
-    doc = name: 'tobi'
+    doc = name: 'Tur til Bergen', lisens: 'CC BY-NC 3.0 NO', status: 'Offentlig'
     req.post('/turer?api_key=dnt').send(doc)
       .expect(201)
       .end (err, res) ->
         throw err if err
-        assert.equal res.body.documents.length, 1
         assert.equal res.body.count, 1
-        assert.equal typeof res.body.documents[0], 'string'
+        assert.equal typeof res.body.document, 'object'
 
         req.get('/turer?api_key=dnt')
           .expect(200)

        throw err if err

        for doc in res.body.documents
          assert.equal Object.keys(doc).length, 3
          assert.equal typeof doc._id, 'string'
          assert.equal typeof doc.navn, 'string'
          assert.equal typeof doc.endret, 'string'

        done()


            assert.equal res.body.total, 101, 'there should be total of 101 documents in collection'
            done()

  it 'should handle rapid requests to collection', (done) ->
    this.timeout(5000)

    count = 0
    target = 200
    for i in [1..target]
      req.post('/turer?api_key=dnt').send({num:i}).expect(201).end (err, res) ->
        throw err if err
        assert.equal res.body.count, 1
        assert.equal typeof res.body.document, 'object'
        done() if ++count is target

  it 'should convert _id to ObjectID if provided with one', (done) ->
    doc = _id: new ObjectID().toString(), name: 'tuut-tuut'
    req.post('/turer?api_key=dnt').send(doc).expect(201).end (err, res) ->
      throw err if err
      assert.equal res.body.document._id, doc._id
      done()

  it 'should update existing document', (done) ->
    doc = {_id: data[50]._id, navn: 'foo'}
    req.post('/turer?api_key=dnt').send(doc).expect(201).end (err, res) ->
      throw err if err
      assert.equal res.body.document._id, doc._id
      done()

  it 'should precache new documents', (done) ->
    req.post('/turer?api_key=dnt').send({ navn: 'foo' })
      .expect(201)
      .end (err, res) ->
        throw err if err
        req.get('/turer/' + res.body.document._id + '?api_key=dnt')
          .expect(200)
          .expect('X-Cache-Hit', 'true', done)

  it 'should warn about missing fields', (done) ->
    req.post('/turer?api_key=dnt').send({ navn: 'foo' })
      .expect(201)
      .end (err, res) ->
        throw err if err
        assert res.body.warnings, [
          {
            resource: 'turer'
            field: 'lisens'
            value: 'CC BY-ND-NC 3.0 NO'
            code: 'missing_field'
          }, {
            resource: 'turer'
            field: 'status'
            value: 'Kladd'
            code: 'missing_field'
          }
        ]
        done()

  it 'should return error for missing request body', (done) ->
    req.post('/turer?api_key=dnt').expect(400, done)

  it 'should return error if request body is an array', (done) ->
    req.post('/turer?api_key=dnt').send([{navn: 'foo'}]).expect(422, done)

describe 'PUT', ->
  it 'should not be implemeted', (done) ->
