 # connection to DB for "hand work"
 cradle = require 'cradle'
 connection = new cradle.Connection
-    cache: true,
+    cache: false,
     raw: false
 db = connection.database('cozy')
 

                    done()

            it "Then error 404 should be returned", ->
                @response.statusCode.should.equal 404
        
        describe "Access to an existing view : no_doc", ->
            before cleanRequest

            it "When I send a request to access view no_doc", (done) ->
                client.get "request/no_doc/", (error, response, body) =>
                    response.statusCode.should.equal 200
                    @body = parseBody response, body
                    done()

            it "Then I should have no document returned", ->
                @body.should.be.empty

        describe "Access to an existing view : every_docs", (done) ->
            before cleanRequest




    describe "View creation", ->
        describe "Creation of the first view + design document creation", ->
            before cleanRequest

            it "When I send a request to create view every_docs", (done) ->
                map = (doc) ->
                    emit doc._id, doc
                    return
                @viewAll = {map:map.toString()}

                client.put 'request/every_docs/', @viewAll, \
                        (error, response, body) =>
                    response.statusCode.should.equal 200
                    done()
            
            it "Then the design document should exist and contain the view", \
                    (done) ->
                db.get '_design/cozy-request', (err, res) ->
                    should.not.exist err
                    should.exist res
                    res.views.should.have.property 'every_docs', @viewAll
                    done()

        describe "Creation of a new view", ->
            before cleanRequest

            it "When I send a request to create view even_num", (done) ->
                map = (doc) ->
                    emit doc._id, doc if (doc.num? && (doc.num % 2) is 0)
                    return
                @viewEven = {map:map.toString()}

                client.put 'request/even_num/', @viewEven, \
                        (error, response, body) =>
                    response.statusCode.should.equal 200
                    done()

            it "Then the design document should exist and contain the views", \
                    (done) ->
                db.get '_design/cozy-request', (err, res) ->
                    should.not.exist err
                    should.exist res
                    res.views.should.have.property 'every_docs', @viewAll
                    res.views.should.have.property 'even_num', @viewEven
                    done()

    describe "Access to a view without option", ->
        describe "Access to a non existing view", ->
            before cleanRequest
