       user.age.should.be.equal(3)
       user.content.should.be.equal('test')
       user.id.should.not.be.null
+
       done()
 
   it 'should support Buffer type', (done) ->

      }
    });

    User.hasMany(Post);
    Post.belongsTo(User);


  it 'should have created simple User models', (done) ->


      User.findById u.id, (e, user) ->
        done e if e
        user.icon.should.be.an.instanceOf(Buffer)

        done()

  it 'hasMany should support additional conditions', (done) ->

    User.create {}, (e, u) ->
      u.posts.create (e, p) ->
        u.posts {where: {id: p.id}}, (err, posts) ->
          should.not.exist(err)
          posts.should.have.lengthOf(1)

          done()

  it 'create should return id field but not arangodb _key', (done) ->

    Post.create {title: 'Post1', content: 'Post content'}, (err, post) ->
      should.not.exist(err)
      should.exist(post.id)
      should.not.exist(post._key)
      should.not.exist(post._id)

      done()

  it 'should allow to find by id string', (done) ->

    Post.create {title: 'Post1', content: 'Post content'}, (err, post) ->
      Post.findById post.id.toString(), (err, p) ->
        should.not.exist(err)
        should.exist(p)

        done()

  it 'should allow custom collection name', (done) ->

    Post.create {title: 'Post1', content: 'Post content'}, (err, post) ->
      Post.dataSource.connector.db.collection('PostCollection').findOne {id: post.id}, (err, p) ->
        should.not.exist(err)
        should.exist(p)

        done()

  it 'should allow to find by id using where', (done) ->

    Post.create {title: 'Post1', content: 'Post1 content'}, (err, p1) ->
      Post.create {title: 'Post2', content: 'Post2 content'}, (err, p2) ->
        Post.find {where: {id: p1.id}}, (err, p) ->
          should.not.exist(err)
          should.exist(p && p[0])
          p.length.should.be.equal(1)
          #Not strict equal
          p[0].id.should.be.eql(p1.id)

          done()

  it 'should allow to find by id using where inq', (done) ->

    Post.create {title: 'Post1', content: 'Post1 content'}, (err, p1) ->
      Post.create {title: 'Post2', content: 'Post2 content'}, (err, p2) ->
        Post.find {where: {id: {inq: [p1.id]}}}, (err, p) ->
          should.not.exist(err)
          should.exist(p && p[0])
          p.length.should.be.equal(1)
          #Not strict equal
          p[0].id.should.be.eql(p1.id)

          done()

  it 'should invoke hooks', (done) ->

    events = [];
    connector = Post.getDataSource().connector;
    connector.observe 'before execute', (ctx, next) ->
      ctx.req.command.should.be.string;
      ctx.req.params.should.be.array;
      events.push 'before execute ' + ctx.req.command
      next()

    connector.observe 'after execute', (ctx, next) ->
      ctx.res.should.be.object
      events.push 'after execute ' + ctx.req.command
      next()

    Post.create {title: 'Post1', content: 'Post1 content'}, (err, p1) ->
      Post.find (err, results) ->
        events.should.eql(['before execute insert', 'after execute insert',
          'before execute find', 'after execute find'])
        connector.clearObservers 'before execute'
        connector.clearObservers 'after execute'

        done(err, results)

  it 'should allow to find by number id using where', (done) ->
    PostWithNumberId.create {id: 1, title: 'Post1', content: 'Post1 content'}, (err, p1) ->
      PostWithNumberId.create {id: 2, title: 'Post2', content: 'Post2 content'}, (err, p2) ->
        PostWithNumberId.find {where: {id: p1.id}}, (err, p) ->
          should.not.exist(err)
          should.exist(p && p[0])
          p.length.should.be.equal(1)
          p[0].id.should.be.eql(p1.id)

          done()

  it 'should allow to find by number id using where inq', (done) ->
    PostWithNumberId.create {id: 1, title: 'Post1', content: 'Post1 content'}, (err, p1) ->
      PostWithNumberId.create {id: 2, title: 'Post2', content: 'Post2 content'}, (err, p2) ->
        PostWithNumberId.find {where: {id: {inq: [1]}}}, (err, p) ->
          should.not.exist(err)
          should.exist(p && p[0])
          p.length.should.be.equal(1)
          p[0].id.should.be.eql(p1.id)
        PostWithNumberId.find {where: {id: {inq: [1, 2]}}}, (err, p) ->
          should.not.exist(err)
          p.length.should.be.equal(2)
          p[0].id.should.be.eql(p1.id)
          p[1].id.should.be.eql(p2.id)
        PostWithNumberId.find {where: {id: {inq: [0]}}}, (err, p) ->
          should.not.exist(err)
          p.length.should.be.equal(0)

      done()

  it 'save should not return arangodb _key', (done) ->
    Post.create {title: 'Post1', content: 'Post content'}, (err, post) ->
      post.content = 'AAA'
      post.save (err, p) ->
        should.not.exist(err)
        should.not.exist(p._key)
        p.id.should.be.equal(post.id)
        p.content.should.be.equal('AAA')

        done()

  it 'find should return an object with an id, which is instanceof String, but not arangodb _key', (done) ->
    Post.create {title: 'Post1', content: 'Post content'}, (err, post) ->
      Post.findById post.id, (err, post) ->
        should.not.exist(err)
        post.id.should.be.an.instanceOf(String)
        should.not.exist(post._key)

        done()
