<commit_before>describe('basic', function (){

  var app
    , model;

  before(function (done) {
    app = require('cantina');
    app.boot(function(err) {
      app.conf.set('mongo:db', 'cantina-models-mongo-test-' + idgen());
      require('../');
      if (err) return done(err);
      app.start(done);
    });
  });

  after(function (done) {
    app.mongo.dropDatabase(function () {
      app.destroy(done);
    });
  });

  describe('core', function () {
    it('can create a mongo collection factory', function () {
      assert(app.createMongoCollection);
      assert('function' === typeof app.createMongoCollection);
    });

    it('can create a collection', function () {
      app.createMongoCollection('people');
      assert(app.collections.people);
    });

    it('can create a model', function () {
      model = app.collections.people.create({
        first: 'Brian',
        last: 'Link',
        email: '<EMAIL>'
      });
      assert(model);
      assert(model.id);
      assert.equal(model.rev, 0);
    });
    it('can save a new model', function (done) {
      app.collections.people.save(model, function (err, brian) {
        assert.ifError(err);
        assert.equal(brian.first, 'Brian');
        assert.equal(brian.last, 'Link');
        assert.equal(brian.email, '<EMAIL>');
        assert.equal(model.rev, 1);
        model = brian;
        done();
      });
    });
    it('can save changes to an existing model', function (done) {
      model.first = 'Midnight';
      model.last = 'Rider';
      email = model.email;
      app.collections.people.save(model, function (err, saveModel) {
        assert.ifError(err);
        assert.equal(saveModel.first, 'Midnight');
        assert.equal(saveModel.last, 'Rider');
        assert.equal(saveModel.email, email);
        assert.equal(saveModel.rev, 2);
        done();
      });
    });
    it('adds _changed hash when changing an existing model', function (done) {
      model.first = 'Ultimate';
      model.last = 'Warrior';
      app.collections.people.save(model, function (err, saveModel) {
        assert.ifError(err);
        assert.equal(saveModel.first, 'Ultimate');
        assert.equal(saveModel.last, 'Warrior');
        assert(saveModel._changed.first);
        assert(saveModel._changed.last);
        assert(!saveModel._changed._id);
        assert(!saveModel._changed._changed);
        done();
      });
    });
    it('can load a model', function (done) {
      app.collections.people.load(model.id, function (err, loadModel) {
        assert.ifError(err);
        Object.keys(loadModel).forEach(function (prop) {
          if (prop === '_id') assert(loadModel[prop].equals(model[prop]));
          else if (prop === 'created' || prop === 'updated') assert.equal(loadModel[prop].toString(), model[prop].toString());
          else assert.equal(loadModel[prop], model[prop]);
        });
        done();
      });
    });
    it('can list models', function (done) {
      app.collections.people.list(function (err, list) {
        assert.ifError(err);
        assert(Array.isArray(list));
        assert.equal(list.length, 1);
        assert.equal(list[0].id, model.id);
        done();
      });
    });
    it('can save partial changes to an existing model', function (done) {
      var attrs = {
        id: model.id,
        rev: model.rev,
        first: 'Ultimate',
        last: 'Warrior'
      };
      app.collections.people.save(attrs, function (err, saveModel) {
        assert.ifError(err);
        assert.equal(saveModel.first, 'Ultimate');
        assert.equal(saveModel.last, 'Warrior');
        assert.equal(saveModel.email, model.email);
        assert.equal(saveModel.rev, 3);
        done();
      });
    });
    it('can destroy a model', function (done) {
      app.collections.people.load(model.id, function (err, getModel) {
        assert.ifError(err);
        app.collections.people.destroy(getModel, function (err) {
          assert.ifError(err);
          // verify it's gone
          app.collections.people.load(model.id, function (err, loadModel) {
            assert.ifError(err);
            assert.equal(loadModel, null);
            done();
          });
        });
      });
    });
  });
<commit_msg>Fix tests<commit_after>describe('basic', function (){

  var app
    , model;

  before(function (done) {
    app = require('cantina');
    app.boot(function(err) {
      app.conf.set('mongo:db', 'cantina-models-mongo-test-' + idgen());
      require('../');
      if (err) return done(err);
      app.start(done);
    });
  });

  after(function (done) {
    app.mongo.dropDatabase(function () {
      app.destroy(done);
    });
  });

  describe('core', function () {
    it('can create a mongo collection factory', function () {
      assert(app.createMongoCollection);
      assert('function' === typeof app.createMongoCollection);
    });

    it('can create a collection', function () {
      app.createMongoCollection('people');
      assert(app.collections.people);
    });

    it('can create a model', function () {
      model = app.collections.people.create({
        first: 'Brian',
        last: 'Link',
        email: '<EMAIL>'
      });
      assert(model);
      assert(model.id);
      assert.equal(model.rev, 0);
    });
    it('can save a new model', function (done) {
      app.collections.people.save(model, function (err, brian) {
        assert.ifError(err);
        assert.equal(brian.first, 'Brian');
        assert.equal(brian.last, 'Link');
        assert.equal(brian.email, '<EMAIL>');
        assert.equal(model.rev, 1);
        model = brian;
        done();
      });
    });
    it('can save changes to an existing model', function (done) {
      model.first = 'Midnight';
      model.last = 'Rider';
      email = model.email;
      app.collections.people.save(model, function (err, saveModel) {
        assert.ifError(err);
        assert.equal(saveModel.first, 'Midnight');
        assert.equal(saveModel.last, 'Rider');
        assert.equal(saveModel.email, email);
        assert.equal(saveModel.rev, 2);
        done();
      });
    });
    it('adds _changed hash when changing an existing model', function (done) {
      model.first = 'Ultimate';
      model.last = 'Warrior';
      app.collections.people.save(model, function (err, saveModel) {
        assert.ifError(err);
        assert.equal(saveModel.first, 'Ultimate');
        assert.equal(saveModel.last, 'Warrior');
        assert.equal(saveModel.rev, 3);
        assert(saveModel._changed.first);
        assert(saveModel._changed.last);
        assert(!saveModel._changed._id);
        assert(!saveModel._changed._changed);
        done();
      });
    });
    it('can load a model', function (done) {
      app.collections.people.load(model.id, function (err, loadModel) {
        assert.ifError(err);
        Object.keys(loadModel).forEach(function (prop) {
          if (prop === '_id') assert(loadModel[prop].equals(model[prop]));
          else if (prop === 'created' || prop === 'updated') assert.equal(loadModel[prop].toString(), model[prop].toString());
          else assert.equal(loadModel[prop], model[prop]);
        });
        done();
      });
    });
    it('can list models', function (done) {
      app.collections.people.list(function (err, list) {
        assert.ifError(err);
        assert(Array.isArray(list));
        assert.equal(list.length, 1);
        assert.equal(list[0].id, model.id);
        done();
      });
    });
    it('can save partial changes to an existing model', function (done) {
      var attrs = {
        id: model.id,
        rev: model.rev,
        first: 'Ultimate',
        last: 'Warrior'
      };
      app.collections.people.save(attrs, function (err, saveModel) {
        assert.ifError(err);
        assert.equal(saveModel.first, 'Ultimate');
        assert.equal(saveModel.last, 'Warrior');
        assert.equal(saveModel.email, model.email);
        assert.equal(saveModel.rev, 4);
        done();
      });
    });
    it('can destroy a model', function (done) {
      app.collections.people.load(model.id, function (err, getModel) {
        assert.ifError(err);
        app.collections.people.destroy(getModel, function (err) {
          assert.ifError(err);
          // verify it's gone
          app.collections.people.load(model.id, function (err, loadModel) {
            assert.ifError(err);
            assert.equal(loadModel, null);
            done();
          });
        });
      });
    });
  });

{'fraction_non_alphanumeric': 0.16212406015037595, 'fraction_numerical': 0.0015272556390977443, 'mean_word_length': 2.380857823669579, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3570440', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2552, 'n_words': 491}