   test.equal Person.Meta._name, 'Person'
   test.equal Person.Meta.parent, _TestPerson.Meta
   test.equal Person.Meta.document, Person
-  test.equal Person.Meta._name, 'Person'
   test.equal Person.Meta.collection._name, 'Persons'
   test.equal _.size(Person.Meta.triggers), 0
   test.equal _.size(Person.Meta.fields), 5

  Meteor.call 'wait-for-database', expect (error) ->
    test.isFalse error, error?.toString?() or error

ALL = @ALL = [User, UserLink, CircularFirst, CircularSecond, SpecialPerson, Recursive, IdentityGenerator, SpecialPost, Post, Person, PostLink, SubfieldItem]

testDocumentList = (test, list) ->
  test.equal Document.list, list, "expected: #{ (d.Meta._name for d in list) } vs. actual: #{ (d.Meta._name for d in Document.list) }"

  test.equal SpecialPost.Meta.fields.special.reverseFields, []
  test.isTrue SpecialPost.Meta._observersSetup

  test.equal LocalPost.Meta._name, 'LocalPost'
  test.equal LocalPost.Meta.document, LocalPost
  test.isNull LocalPost.Meta.collection._name
  test.equal _.size(LocalPost.Meta.triggers), 1
  test.instanceOf LocalPost.Meta.triggers.testTrigger, LocalPost._Trigger
  test.equal LocalPost.Meta.triggers.testTrigger.name, 'testTrigger'
  test.equal LocalPost.Meta.triggers.testTrigger.document, LocalPost
  test.isNull LocalPost.Meta.triggers.testTrigger.collection._name
  test.equal LocalPost.Meta.triggers.testTrigger.fields, ['body']
  test.equal _.size(LocalPost.Meta.fields), 7
  test.instanceOf LocalPost.Meta.fields.author, LocalPost._ReferenceField
  test.isNull LocalPost.Meta.fields.author.ancestorArray, LocalPost.Meta.fields.author.ancestorArray
  test.isTrue LocalPost.Meta.fields.author.required
  test.equal LocalPost.Meta.fields.author.sourcePath, 'author'
  test.equal LocalPost.Meta.fields.author.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.author.targetDocument, LocalPerson
  test.isNull LocalPost.Meta.fields.author.sourceCollection._name
  test.isNull LocalPost.Meta.fields.author.targetCollection._name
  test.isNull LocalPost.Meta.fields.author.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.author.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.author.fields, ['username', 'displayName', 'field1', 'field2']
  test.equal LocalPost.Meta.fields.author.reverseName, 'posts'
  test.equal LocalPost.Meta.fields.author.reverseFields, ['body', 'subdocument.body', 'nested.body']
  test.instanceOf LocalPost.Meta.fields.subscribers, LocalPost._ReferenceField
  test.equal LocalPost.Meta.fields.subscribers.ancestorArray, 'subscribers'
  test.isTrue LocalPost.Meta.fields.subscribers.required
  test.equal LocalPost.Meta.fields.subscribers.sourcePath, 'subscribers'
  test.equal LocalPost.Meta.fields.subscribers.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.subscribers.targetDocument, LocalPerson
  test.isNull LocalPost.Meta.fields.subscribers.sourceCollection._name
  test.isNull LocalPost.Meta.fields.subscribers.targetCollection._name
  test.isNull LocalPost.Meta.fields.subscribers.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.subscribers.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.subscribers.fields, []
  test.isNull LocalPost.Meta.fields.subscribers.reverseName
  test.equal LocalPost.Meta.fields.subscribers.reverseFields, []
  test.instanceOf LocalPost.Meta.fields.reviewers, LocalPost._ReferenceField
  test.equal LocalPost.Meta.fields.reviewers.ancestorArray, 'reviewers'
  test.isTrue LocalPost.Meta.fields.reviewers.required
  test.equal LocalPost.Meta.fields.reviewers.sourcePath, 'reviewers'
  test.equal LocalPost.Meta.fields.reviewers.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.reviewers.targetDocument, LocalPerson
  test.isNull LocalPost.Meta.fields.reviewers.sourceCollection._name
  test.isNull LocalPost.Meta.fields.reviewers.targetCollection._name
  test.isNull LocalPost.Meta.fields.reviewers.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.reviewers.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.reviewers.fields, [username: 1]
  test.isNull LocalPost.Meta.fields.reviewers.reverseName
  test.equal LocalPost.Meta.fields.reviewers.reverseFields, []
  test.equal _.size(LocalPost.Meta.fields.subdocument), 3
  test.instanceOf LocalPost.Meta.fields.subdocument.person, LocalPost._ReferenceField
  test.isNull LocalPost.Meta.fields.subdocument.person.ancestorArray, LocalPost.Meta.fields.subdocument.person.ancestorArray
  test.isFalse LocalPost.Meta.fields.subdocument.person.required
  test.equal LocalPost.Meta.fields.subdocument.person.sourcePath, 'subdocument.person'
  test.equal LocalPost.Meta.fields.subdocument.person.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.subdocument.person.targetDocument, LocalPerson
  test.isNull LocalPost.Meta.fields.subdocument.person.sourceCollection._name
  test.isNull LocalPost.Meta.fields.subdocument.person.targetCollection._name
  test.isNull LocalPost.Meta.fields.subdocument.person.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.subdocument.person.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.subdocument.person.fields, {'username': 1, 'displayName': 1, 'field1': 1, 'field2': 1}
  test.equal LocalPost.Meta.fields.subdocument.person.reverseName, 'subdocumentPosts'
  test.equal LocalPost.Meta.fields.subdocument.person.reverseFields, ['body', 'subdocument.body', 'nested.body']
  test.instanceOf LocalPost.Meta.fields.subdocument.persons, LocalPost._ReferenceField
  test.equal LocalPost.Meta.fields.subdocument.persons.ancestorArray, 'subdocument.persons'
  test.isTrue LocalPost.Meta.fields.subdocument.persons.required
  test.equal LocalPost.Meta.fields.subdocument.persons.sourcePath, 'subdocument.persons'
  test.equal LocalPost.Meta.fields.subdocument.persons.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.subdocument.persons.targetDocument, LocalPerson
  test.isNull LocalPost.Meta.fields.subdocument.persons.sourceCollection._name
  test.isNull LocalPost.Meta.fields.subdocument.persons.targetCollection._name
  test.isNull LocalPost.Meta.fields.subdocument.persons.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.subdocument.persons.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.subdocument.persons.fields, ['username', 'displayName', 'field1', 'field2']
  test.equal LocalPost.Meta.fields.subdocument.persons.reverseName, 'subdocumentsPosts'
  test.equal LocalPost.Meta.fields.subdocument.persons.reverseFields, ['body', 'subdocument.body', 'nested.body']
  test.instanceOf LocalPost.Meta.fields.subdocument.slug, LocalPost._GeneratedField
  test.isNull LocalPost.Meta.fields.subdocument.slug.ancestorArray, LocalPost.Meta.fields.subdocument.slug.ancestorArray
  test.isTrue _.isFunction LocalPost.Meta.fields.subdocument.slug.generator
  test.equal LocalPost.Meta.fields.subdocument.slug.sourcePath, 'subdocument.slug'
  test.equal LocalPost.Meta.fields.subdocument.slug.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.subdocument.slug.targetDocument, LocalPost
  test.isNull LocalPost.Meta.fields.subdocument.slug.sourceCollection._name
  test.isNull LocalPost.Meta.fields.subdocument.slug.targetCollection._name
  test.isNull LocalPost.Meta.fields.subdocument.slug.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.subdocument.slug.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.subdocument.slug.fields, ['body', 'subdocument.body']
  test.isUndefined LocalPost.Meta.fields.subdocument.slug.reverseName
  test.isUndefined LocalPost.Meta.fields.subdocument.slug.reverseFields
  test.equal _.size(LocalPost.Meta.fields.nested), 3
  test.instanceOf LocalPost.Meta.fields.nested.required, LocalPost._ReferenceField
  test.equal LocalPost.Meta.fields.nested.required.ancestorArray, 'nested'
  test.isTrue LocalPost.Meta.fields.nested.required.required
  test.equal LocalPost.Meta.fields.nested.required.sourcePath, 'nested.required'
  test.equal LocalPost.Meta.fields.nested.required.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.nested.required.targetDocument, LocalPerson
  test.isNull LocalPost.Meta.fields.nested.required.sourceCollection._name
  test.isNull LocalPost.Meta.fields.nested.required.targetCollection._name
  test.isNull LocalPost.Meta.fields.nested.required.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.nested.required.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.nested.required.fields, ['username', 'displayName', 'field1', 'field2']
  test.equal LocalPost.Meta.fields.nested.required.reverseName, 'nestedPosts'
  test.equal LocalPost.Meta.fields.nested.required.reverseFields, ['body', 'subdocument.body', 'nested.body']
  test.instanceOf LocalPost.Meta.fields.nested.optional, LocalPost._ReferenceField
  test.equal LocalPost.Meta.fields.nested.optional.ancestorArray, 'nested'
  test.isFalse LocalPost.Meta.fields.nested.optional.required
  test.equal LocalPost.Meta.fields.nested.optional.sourcePath, 'nested.optional'
  test.equal LocalPost.Meta.fields.nested.optional.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.nested.optional.targetDocument, LocalPerson
  test.isNull LocalPost.Meta.fields.nested.optional.sourceCollection._name
  test.isNull LocalPost.Meta.fields.nested.optional.targetCollection._name
  test.isNull LocalPost.Meta.fields.nested.optional.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.nested.optional.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.nested.optional.fields, ['username']
  test.isNull LocalPost.Meta.fields.nested.optional.reverseName
  test.equal LocalPost.Meta.fields.nested.optional.reverseFields, []
  test.instanceOf LocalPost.Meta.fields.nested.slug, LocalPost._GeneratedField
  test.equal LocalPost.Meta.fields.nested.slug.ancestorArray, 'nested'
  test.isTrue _.isFunction LocalPost.Meta.fields.nested.slug.generator
  test.equal LocalPost.Meta.fields.nested.slug.sourcePath, 'nested.slug'
  test.equal LocalPost.Meta.fields.nested.slug.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.nested.slug.targetDocument, LocalPost
  test.isNull LocalPost.Meta.fields.nested.slug.sourceCollection._name
  test.isNull LocalPost.Meta.fields.nested.slug.targetCollection._name
  test.isNull LocalPost.Meta.fields.nested.slug.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.nested.slug.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.nested.slug.fields, ['body', 'nested.body']
  test.isUndefined LocalPost.Meta.fields.nested.slug.reverseName
  test.isUndefined LocalPost.Meta.fields.nested.slug.reverseFields
  test.instanceOf LocalPost.Meta.fields.slug, LocalPost._GeneratedField
  test.isNull LocalPost.Meta.fields.slug.ancestorArray, LocalPost.Meta.fields.slug.ancestorArray
  test.isTrue _.isFunction LocalPost.Meta.fields.slug.generator
  test.equal LocalPost.Meta.fields.slug.sourcePath, 'slug'
  test.equal LocalPost.Meta.fields.slug.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.slug.targetDocument, LocalPost
  test.isNull LocalPost.Meta.fields.slug.sourceCollection._name
  test.isNull LocalPost.Meta.fields.slug.targetCollection._name
  test.isNull LocalPost.Meta.fields.slug.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.slug.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.slug.fields, ['body', 'subdocument.body']
  test.isUndefined LocalPost.Meta.fields.slug.reverseName
  test.isUndefined LocalPost.Meta.fields.slug.reverseFields
  test.instanceOf LocalPost.Meta.fields.tags, LocalPost._GeneratedField
  test.equal LocalPost.Meta.fields.tags.ancestorArray, 'tags'
  test.isTrue _.isFunction LocalPost.Meta.fields.tags.generator
  test.equal LocalPost.Meta.fields.tags.sourcePath, 'tags'
  test.equal LocalPost.Meta.fields.tags.sourceDocument, LocalPost
  test.equal LocalPost.Meta.fields.tags.targetDocument, LocalPost
  test.isNull LocalPost.Meta.fields.tags.sourceCollection._name
  test.isNull LocalPost.Meta.fields.tags.targetCollection._name
  test.isNull LocalPost.Meta.fields.tags.sourceDocument.Meta.collection._name
  test.isNull LocalPost.Meta.fields.tags.targetDocument.Meta.collection._name
  test.equal LocalPost.Meta.fields.tags.fields, ['body', 'subdocument.body', 'nested.body']
  test.isUndefined LocalPost.Meta.fields.tags.reverseName
  test.isUndefined LocalPost.Meta.fields.tags.reverseFields
  test.isTrue LocalPost.Meta._observersSetup

  test.equal LocalPerson.Meta._name, 'LocalPerson'
  test.equal LocalPerson.Meta.document, LocalPerson
  test.isNull LocalPerson.Meta.collection._name
  test.equal _.size(LocalPerson.Meta.triggers), 0
  test.equal _.size(LocalPerson.Meta.fields), 5
  test.instanceOf LocalPerson.Meta.fields.posts, LocalPerson._ReferenceField
  test.equal LocalPerson.Meta.fields.posts.ancestorArray, 'posts'
  test.isTrue LocalPerson.Meta.fields.posts.required
  test.equal LocalPerson.Meta.fields.posts.sourcePath, 'posts'
  test.equal LocalPerson.Meta.fields.posts.sourceDocument, LocalPerson
  test.equal LocalPerson.Meta.fields.posts.targetDocument, LocalPost
  test.isNull LocalPerson.Meta.fields.posts.sourceCollection._name
  test.isNull LocalPerson.Meta.fields.posts.targetCollection._name
  test.isNull LocalPerson.Meta.fields.posts.sourceDocument.Meta.collection._name
  test.isNull LocalPerson.Meta.fields.posts.targetDocument.Meta.collection._name
  test.equal LocalPerson.Meta.fields.posts.fields, ['body', 'subdocument.body', 'nested.body']
  test.isNull LocalPerson.Meta.fields.posts.reverseName
  test.equal LocalPerson.Meta.fields.posts.reverseFields, []
  test.instanceOf LocalPerson.Meta.fields.nestedPosts, LocalPerson._ReferenceField
  test.equal LocalPerson.Meta.fields.nestedPosts.ancestorArray, 'nestedPosts'
  test.isTrue LocalPerson.Meta.fields.nestedPosts.required
  test.equal LocalPerson.Meta.fields.nestedPosts.sourcePath, 'nestedPosts'
  test.equal LocalPerson.Meta.fields.nestedPosts.sourceDocument, LocalPerson
  test.equal LocalPerson.Meta.fields.nestedPosts.targetDocument, LocalPost
  test.isNull LocalPerson.Meta.fields.nestedPosts.sourceCollection._name
  test.isNull LocalPerson.Meta.fields.nestedPosts.targetCollection._name
  test.isNull LocalPerson.Meta.fields.nestedPosts.sourceDocument.Meta.collection._name
  test.isNull LocalPerson.Meta.fields.nestedPosts.targetDocument.Meta.collection._name
  test.equal LocalPerson.Meta.fields.nestedPosts.fields, ['body', 'subdocument.body', 'nested.body']
  test.isNull LocalPerson.Meta.fields.nestedPosts.reverseName
  test.equal LocalPerson.Meta.fields.nestedPosts.reverseFields, []
  test.instanceOf LocalPerson.Meta.fields.count, LocalPerson._GeneratedField
  test.isNull LocalPerson.Meta.fields.count.ancestorArray, LocalPerson.Meta.fields.count.ancestorArray
  test.isTrue _.isFunction LocalPerson.Meta.fields.count.generator
  test.equal LocalPerson.Meta.fields.count.sourcePath, 'count'
  test.equal LocalPerson.Meta.fields.count.sourceDocument, LocalPerson
  test.equal LocalPerson.Meta.fields.count.targetDocument, LocalPerson
  test.isNull LocalPerson.Meta.fields.count.sourceCollection._name
  test.isNull LocalPerson.Meta.fields.count.targetCollection._name
  test.isNull LocalPerson.Meta.fields.count.sourceDocument.Meta.collection._name
  test.isNull LocalPerson.Meta.fields.count.targetDocument.Meta.collection._name
  test.equal LocalPerson.Meta.fields.count.fields, ['posts', 'subdocumentPosts', 'subdocumentsPosts', 'nestedPosts']
  test.isUndefined LocalPerson.Meta.fields.count.reverseName
  test.isUndefined LocalPerson.Meta.fields.count.reverseFields
  test.instanceOf LocalPerson.Meta.fields.subdocumentPosts, LocalPerson._ReferenceField
  test.equal LocalPerson.Meta.fields.subdocumentPosts.ancestorArray, 'subdocumentPosts'
  test.isTrue LocalPerson.Meta.fields.subdocumentPosts.required
  test.equal LocalPerson.Meta.fields.subdocumentPosts.sourcePath, 'subdocumentPosts'
  test.equal LocalPerson.Meta.fields.subdocumentPosts.sourceDocument, LocalPerson
  test.equal LocalPerson.Meta.fields.subdocumentPosts.targetDocument, LocalPost
  test.isNull LocalPerson.Meta.fields.subdocumentPosts.sourceCollection._name
  test.isNull LocalPerson.Meta.fields.subdocumentPosts.targetCollection._name
  test.isNull LocalPerson.Meta.fields.subdocumentPosts.sourceDocument.Meta.collection._name
  test.isNull LocalPerson.Meta.fields.subdocumentPosts.targetDocument.Meta.collection._name
  test.equal LocalPerson.Meta.fields.subdocumentPosts.fields, ['body', 'subdocument.body', 'nested.body']
  test.isNull LocalPerson.Meta.fields.subdocumentPosts.reverseName
  test.equal LocalPerson.Meta.fields.subdocumentPosts.reverseFields, []
  test.instanceOf LocalPerson.Meta.fields.subdocumentsPosts, LocalPerson._ReferenceField
  test.equal LocalPerson.Meta.fields.subdocumentsPosts.ancestorArray, 'subdocumentsPosts'
  test.isTrue LocalPerson.Meta.fields.subdocumentsPosts.required
  test.equal LocalPerson.Meta.fields.subdocumentsPosts.sourcePath, 'subdocumentsPosts'
  test.equal LocalPerson.Meta.fields.subdocumentsPosts.sourceDocument, LocalPerson
  test.equal LocalPerson.Meta.fields.subdocumentsPosts.targetDocument, LocalPost
  test.isNull LocalPerson.Meta.fields.subdocumentsPosts.sourceCollection._name
  test.isNull LocalPerson.Meta.fields.subdocumentsPosts.targetCollection._name
  test.isNull LocalPerson.Meta.fields.subdocumentsPosts.sourceDocument.Meta.collection._name
  test.isNull LocalPerson.Meta.fields.subdocumentsPosts.targetDocument.Meta.collection._name
  test.equal LocalPerson.Meta.fields.subdocumentsPosts.fields, ['body', 'subdocument.body', 'nested.body']
  test.isNull LocalPerson.Meta.fields.subdocumentsPosts.reverseName
  test.equal LocalPerson.Meta.fields.subdocumentsPosts.reverseFields, []
  test.isTrue LocalPerson.Meta._observersSetup

  testDocumentList test, ALL

plainObject = (obj) ->
