     @partiallyEncryptedDoc.remove (err) ->
       assert.equal err, null
       done()
-
-  it 'should have called encrypt then decrypt', ->
-    assert.equal @partiallyEncryptedDoc.encrypt.callCount, 1
-    assert.equal @partiallyEncryptedDoc.decryptSync.callCount, 1
-    assert @partiallyEncryptedDoc.encrypt.calledBefore @partiallyEncryptedDoc.decryptSync
 
   it 'should have decrypted fields', ->
     assert.equal @partiallyEncryptedDoc.encryptedText, 'Encrypted Text'

        done()

describe 'Array EmbeddedDocument', ->
  before ->
    ChildModelSchema = mongoose.Schema
      text: type: String

    ChildModelSchema.plugin encrypt, key: encryptionKey

    ParentModelSchema = mongoose.Schema
      text: type: String
      children: [ChildModelSchema]

    @ParentModel = mongoose.model 'Parent', ParentModelSchema
    @ChildModel = mongoose.model 'Child', ChildModelSchema

  beforeEach (done) ->
    @parentDoc = new @ParentModel
      text: 'Unencrypted text'

    childDoc = new @ChildModel
      text: 'Child unencrypted text'

    @parentDoc.children.addToSet childDoc

    @parentDoc.save done

  after (done) ->
    @parentDoc.remove done

  describe 'document.save()', ->
    it 'should have decrypted fields', ->
      assert.equal @parentDoc.children[0].text, 'Child unencrypted text'

    it 'should persist children as encrypted', (done) ->
      @ParentModel.find
        _id: @parentDoc._id
        'children._ct': $exists: true
        'children.text': $exists: false
      , (err, docs) ->
        assert.lengthOf docs, 1
        assert.propertyVal docs[0].children[0], 'text', 'Child unencrypted text'
        done()

  describe 'document.find()', ->
    it 'when parent doc found, should pass an unencrypted version of the embedded document to the callback', (done) ->
      @ParentModel.findById @parentDoc._id, (err, doc) ->
        assert.equal err, null
        assert.propertyVal doc, 'text', 'Unencrypted text'
        assert.isArray doc.children
        assert.isObject doc.children[0]
        assert.property doc.children[0], 'text', 'Child unencrypted text'
        assert.property doc.children[0], '_id'
        assert.notProperty doc.children[0], '_ct'
        done()

      encryptedText: 'Encrypted Text'
      unencryptedText: 'Unencrypted Text'

    @partiallyEncryptedDoc.save (err) ->
      assert.equal err, null
      done()
