             ])
 
         it 'should save relations to dedicated hash', ->
-            expect(simpleRelationDefinition.relations).to.have.property('author')
+            expect(relationDefinition.relations).to.have.property('author')
 
         it 'should save relation direction', ->
-            expect(simpleRelationDefinition.relations.author.out).to.have.property('name', 'CREATED_BY')
+            expect(relationDefinition.relations.author.out).to.have.property('name', 'CREATED_BY')
 
         it 'should save relation attributes', ->
-            expect(simpleRelationDefinition.relations.author.out).to.have.property('attributes')
-            expect(simpleRelationDefinition.relations.author.out.attributes).to.contain('when')
+            expect(relationDefinition.relations.author.out).to.have.property('attributes')
+            expect(relationDefinition.relations.author.out.attributes).to.contain('when')
 
         it 'should treat relations as implicit properties declarations', ->
-            expect(simpleRelationDefinition.properties).to.have.property('author')
-            expect(simpleRelationDefinition.properties.author).to.have.property('type', 'User')
+            expect(relationDefinition.properties).to.have.property('author')
+            expect(relationDefinition.properties.author).to.have.property('type', 'User')
 
         it 'should specify what property is managed by relation', ->
-            expect(simpleRelationDefinition.relations.author).to.have.property('property', 'author')
+            expect(relationDefinition.relations.author).to.have.property('property', 'author')
 
         it 'should treat relation attributes as implicit properties declarations', ->
-            expect(simpleRelationDefinition.properties).to.have.property('when').deep.equals
+            expect(relationDefinition.properties).to.have.property('when').deep.equals
                 type: 'object'
                 title: 'DateTime'
 

            ])

        it 'should save indexes to dedicated hash', ->
            expect(simpleIndexSchema.definitions.Tweet).to.have.property('indexes').deep.equals [
                key: [ 'id' ]
                type: 'unique'
            ]

        it 'should add index properties and make them required if necessary', ->
            expect(simpleIndexSchema.definitions.Tweet)
                .to.have.property('properties').deep.equals(id: {})
            expect(simpleIndexSchema.definitions.Tweet)
                .to.have.property('required').deep.equals([ 'id' ])


    describe 'relations', ->
        simpleRelationDefinition = null

        beforeEach ->
            simpleRelationDefinition = postprocessor.postprocess([
                rule: 'relation'
                out:
                    name: 'CREATED_BY'

                    { name: 'latitude' }
                ]
            ])
            enumerationDefinition = simpleEnumerationSchema.definitions.Coordinates

        it 'should describe enumerations as extended definition', ->
            expect(simpleEnumerationSchema.definitions).to.have.property('Coordinates')

        it 'should describe enumeration as arrays with strict item count', ->
            expect(enumerationDefinition).to.have.property('type', 'array')
            expect(enumerationDefinition).to.have.property('maxItems', 2)
            expect(enumerationDefinition).to.have.property('minItems', 2)

        it 'should list array item names', ->
            expect(enumerationDefinition).to.have.property('elements').deep.equal([
                'longitude'
                'latitude'
            ])

        it 'should refer to destructured object definition', ->
            expect(enumerationDefinition).to.have.property('destructuredTo')
            expect(enumerationDefinition.destructuredTo)
                .to.have.property('$ref', '#/definitions/Coordinates/definitions/__Coordinates__')

        it 'should generate definition for object to which array should be converted', ->
            expect(enumerationDefinition.definitions).to.have.property('__Coordinates__')
            
        
        describe 'destructured object definition', ->
            destructuredObjectDefinition = null

            beforeEach ->
                destructuredObjectDefinition =
                    enumerationDefinition.definitions.__Coordinates__
            
            it 'should be a definition', ->
                expect(destructuredObjectDefinition).to.have.property('title', '__Coordinates__')
                expect(destructuredObjectDefinition).to.have.property('type', 'object')

            it 'should describe destructured properties', ->
                expect(destructuredObjectDefinition).to.have.property('properties')
                expect(destructuredObjectDefinition.properties).to.have.property('longitude')
                expect(destructuredObjectDefinition.properties).to.have.property('latitude')

            it 'should restrict properties exactly to what was destructured from array', ->
                expect(destructuredObjectDefinition).to.have.property('additionalProperties', false)
                expect(destructuredObjectDefinition).to.have.property('required').deep.equal([
                    'longitude'
                    'latitude'
                ])


    describe 'indexes', ->
        indexSchema = null

        beforeEach ->
            indexSchema = postprocessor.postprocess([
                type: 'object'
                rule: 'definition'
                isMainDefinition: true
