<commit_before>exports['should correctly receive a change notification for the saved document'] = {
  metadata: { requires: { topology: ['single'] } },
  
  // The actual test we wish to run
  test: function(configure, test) {
    var mapper = require('../../lib/mapper')
      , StringType = require('../../lib/mapper').types.StringType;

    // Start the connection
    var m = mapper.connect(configure.url(), {listenToEvents:true});
    
    // Create a model
    var Cat = m.define('Cat', {
      name: StringType(true, {
          mininumLength: 10
        , maximumLength: 255
      })
    }, {});

    // Wait for connection to happen
    m.on('connect', function() {

      // Clean out the collection for the test
      m.connection.collection('cats').remove({}, function(err) {

        // Create an instance of the model
        var cat = new Cat({name: 'zillow'});

        // Save the cat object
        cat.save(function(err) {
          test.equal(null, err);

          // Register cat instance for change events
          cat.observe();

          // Let's force an update of the cat using the raw driver, causing
          // an document change event to appear in the oplog
          m.connection
            .collection('cats')
            .update({name: 'zillow'}, {$set: {a:1}, $inc: {_rev: 1}}, function(err, result) {
              test.equal(null, err);
              test.equal(1, result.result.n);
            });
        });
        
        // Be notified of changes for the object
        cat.on('change', function(change) {
          if(change.type == 'add') {
            test.equal('a', change.name);
            test.equal(1, change.object[change.name]);
          } else if(change.type == 'update') {
            test.equal('_rev', change.name);
            test.equal(2, change.object[change.name]);
            test.equal(1, change.oldValue);
          }

          // Reload the cat
          cat.reload(function(err) {
            test.equal(null, err);

            m.close();
            test.done();      
          });
        });
      });
    });
  }
}<commit_msg>should correctly update document after field change<commit_after>exports['should correctly receive a change notification for the saved document'] = {
  metadata: { requires: { topology: ['single'] } },
  
  // The actual test we wish to run
  test: function(configure, test) {
    var mapper = require('../../lib/mapper')
      , StringType = require('../../lib/mapper').types.StringType;

    // Start the connection
    var m = mapper.connect(configure.url(), {listenToEvents:true});
    
    // Create a model
    var Cat = m.define('Cat', {
      name: StringType(true, {
          mininumLength: 10
        , maximumLength: 255
      })
    }, {});

    // Wait for connection to happen
    m.on('connect', function() {

      // Clean out the collection for the test
      m.connection.collection('cats').remove({}, function(err) {

        // Create an instance of the model
        var cat = new Cat({name: 'zillow'});

        // Save the cat object
        cat.save(function(err) {
          test.equal(null, err);

          // Register cat instance for change events
          cat.observe();

          // Let's force an update of the cat using the raw driver, causing
          // an document change event to appear in the oplog
          m.connection
            .collection('cats')
            .update({name: 'zillow'}, {$set: {a:1}, $inc: {_rev: 1}}, function(err, result) {
              test.equal(null, err);
              test.equal(1, result.result.n);
            });
        });
        
        // Be notified of changes for the object
        cat.on('change', function(change) {
          if(change.type == 'add') {
            test.equal('a', change.name);
            test.equal(1, change.object[change.name]);
          } else if(change.type == 'update') {
            test.equal('_rev', change.name);
            test.equal(2, change.object[change.name]);
            test.equal(1, change.oldValue);
          }

          // Reload the cat
          cat.reload(function(err) {
            test.equal(null, err);

            m.close();
            test.done();      
          });
        });
      });
    });
  }
}

exports['should correctly update document after field change'] = {
  metadata: { requires: { topology: ['single'] } },
  
  // The actual test we wish to run
  test: function(configure, test) {
    var mapper = require('../../lib/mapper')
      , StringType = require('../../lib/mapper').types.StringType;

    // Start the connection
    var m = mapper.connect(configure.url(), {listenToEvents:true});
    
    // Create a model
    var Cat = m.define('Cat', {
      name: StringType(true, {
          mininumLength: 10
        , maximumLength: 255
      })
    }, {});

    // Wait for connection to happen
    m.on('connect', function() {

      // Clean out the collection for the test
      m.connection.collection('cats').remove({}, function(err) {

        // Create an instance of the model
        var cat = new Cat({name: 'zillow'});

        // Save the cat object
        cat.save(function(err) {
          test.equal(null, err);

          // Register cat instance for change events
          cat.observe();

          // Modify the document field
          cat.name = 'zillow2';

          // Save the changed instance
          cat.save(function(err) {
            test.equal(null, err);

            m.close();
            test.done();      
          });

          // // Let's force an update of the cat using the raw driver, causing
          // // an document change event to appear in the oplog
          // m.connection
          //   .collection('cats')
          //   .update({name: 'zillow'}, {$set: {a:1}, $inc: {_rev: 1}}, function(err, result) {
          //     test.equal(null, err);
          //     test.equal(1, result.result.n);
          //   });
        });
        
        // Be notified of changes for the object
        cat.on('change', function(change) {
          console.log("----------------------------------- change")
          console.dir(change)
          // if(change.type == 'add') {
          //   test.equal('a', change.name);
          //   test.equal(1, change.object[change.name]);
          // } else if(change.type == 'update') {
          //   test.equal('_rev', change.name);
          //   test.equal(2, change.object[change.name]);
          //   test.equal(1, change.oldValue);
          // }

          // // Reload the cat
          // cat.reload(function(err) {
          //   test.equal(null, err);

          //   m.close();
          //   test.done();      
          // });
        });
      });
    });
  }
}
{'fraction_non_alphanumeric': 0.1536976536976537, 'fraction_numerical': 0.005049005049005049, 'mean_word_length': 1.665215670755837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4503296', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1855, 'n_words': 492}