'use strict';

var mongoose = require('mongoose');
var mockgoose = require('mockgoose');
var recent = require('../index');
var chai = require('chai');
chai.should();

mockgoose(mongoose);

describe('mongoose-recent', function() {
  var Schema;

  beforeEach(function() {
    Schema = new mongoose.Schema({}, { strict: false });
  });

  it('should use default options', function() {
    Schema.plugin(recent);
    var Test = mongoose.model('Test', Schema);
    Test.should.eql(Test);
  });
});
@@ -158,16 +158,42 @@
 hould();
+%0Avar expect = chai.expect;
 %0A%0Amockgo
@@ -464,16 +464,21 @@
 el('Test
+Smoke
 ', Schem
@@ -485,32 +485,2170 @@
 a);%0A
+%0A
     
-Test.should.eql(Test
+var testDoc = new Test();%0A    expect(testDoc.recentViews).to.exist;%0A    expect(testDoc.addRecentView).to.exist;%0A    return testDoc.addRecentView(mongoose.Types.ObjectId()).spread(function(me) %7B%0A      expect(me.recentViews%5B0%5D.view).to.exist;%0A      expect(me.recentViews%5B0%5D.date).to.exist;%0A    %7D);%0A  %7D);%0A%0A  it('should allow changing the name and date field name', function() %7B%0A    Schema.plugin(recent, %7Bname: 'play', dateFieldName: 'time'%7D);%0A    var Test = mongoose.model('TestChanging', Schema);%0A%0A    var testDoc = new Test();%0A    expect(testDoc.recentPlays).to.exist;%0A    expect(testDoc.addRecentPlay).to.exist;%0A    return testDoc.addRecentPlay(mongoose.Types.ObjectId()).spread(function(me) %7B%0A      console.log(me);%0A      expect(me.recentPlays%5B0%5D.play).to.exist;%0A      expect(me.recentPlays%5B0%5D.time).to.exist;%0A    %7D);%0A  %7D);%0A%0A  it('should allow fully specifying the schema names', function() %7B%0A    Schema.plugin(recent, %7Bname: 'foo', collectionPath: 'myAwesomeCollection', addFunctionName: 'soYouWantToAdd'%7D);%0A    var Test = mongoose.model('TestFullSpec', Schema);%0A%0A    var testDoc = new Test();%0A    expect(testDoc.myAwesomeCollection).to.exist;%0A    expect(testDoc.soYouWantToAdd).to.exist;%0A    return testDoc.soYouWantToAdd(mongoose.Types.ObjectId()).spread(function(me) %7B%0A      expect(me.myAwesomeCollection%5B0%5D.foo).to.exist;%0A    %7D);%0A  %7D);%0A%0A  it('should not overwrite a field that already exists', function() %7B%0A    var OverwriteSchema = new mongoose.Schema(%7B%0A      recentViews: String%0A    %7D, %7B strict: false %7D);%0A    %0A    OverwriteSchema.plugin(recent);%0A    expect(OverwriteSchema.paths.recentViews.instance).to.eql('String');%0A  %7D);%0A%0A  it('should not allow duplicates by default', function() %7B%0A    Schema.plugin(recent);%0A    var Test = mongoose.model('TestNoDupe', Schema);%0A%0A    var testDoc = new Test();%0A    var id1 = mongoose.Types.ObjectId();%0A    return testDoc.addRecentView(id1).then(function() %7B%0A      return testDoc.addRecentView(mongoose.Types.ObjectId());%0A    %7D).then(function() %7B%0A      return testDoc.addRecentView(id1);%0A    %7D).spread(function(me) %7B%0A      me.recentViews.should.have.length(2);%0A      me.recentViews%5B0%5D.view.should.eql(id1);%0A    %7D
 );%0A 

Add most tests.