it('should return all references data for a View with multiple calls', function (done) {
                var retrieveQueries = new RetrieveQueries($q, Restangular, config, PromisesResolver),
                    post = new Entity('posts'),
                    author = new Entity('authors'),
                    authorRef = new ReferenceField('author');

                var rawPosts = [
                    {id: 1, author: 'abc'},
                    {id: 2, author: '19DFE'}
                ];

                var rawAuthors = [
                    {id: 'abc', name: 'Rollo'},
                    {id: '19DFE', name: 'Ragna'}
                ];

                authorRef.targetEntity(author);
                authorRef.targetField(new Field('name'));
                post.listView()
                    .addField(authorRef);

                spyOn(Restangular, 'get').and.returnValue(mixins.buildPromise(mixins.buildPromise({})));
                spyOn(PromisesResolver, 'allEvenFailed').and.returnValue(mixins.buildPromise([{status: 'success', result: rawAuthors[0] }, { status: 'success', result: rawAuthors[1] }]));

                retrieveQueries.getReferencedData(post.listView().getReferences(), rawPosts)
                    .then(function (referencedData) {
                        expect(referencedData.author.length).toEqual(2);
                        expect(referencedData.author[0].id).toEqual('abc');
                        expect(referencedData.author[1].name).toEqual('Ragna');
                    })
                    .then(done, done.fail);
            });
            it('should fill reference values of a collection', function () {
                var retrieveQueries = new RetrieveQueries({}, Restangular, config, PromisesResolver),
                    entry1 = new Entry(),
                    entry2 = new Entry(),
                    entry3 = new Entry(),
                    human = new Entity('humans'),
                    tag = new Entity('tags'),
                    ref1 = new ReferenceField('human_id'),
                    ref2 = new ReferenceManyField('tags');

                human.editionView().identifier(new Field('id'));
                tag.editionView().identifier(new Field('id'));
                ref1
                    .targetEntity(human)
                    .targetField(new Field('name'));
                ref1.entries = [
                    {values: {id: 1, name: 'Bob'}},
                    {values: {id: 2, name: 'Daniel'}},
                    {values: {id: 3, name: 'Jack'}}
                ];

                ref2
                    .targetEntity(tag)
                    .targetField(new Field('label'));
                ref2.entries = [
                    {values: {id: 1, label: 'Photo'}},
                    {values: {id: 2, label: 'Watch'}},
                    {values: {id: 3, label: 'Panda'}}
                ];

                entry1.values.human_id = 1;
                entry1.values.tags = [1, 3];
                entry2.values.human_id = 1;
                entry2.values.tags = [2];
                entry3.values.human_id = 3;

                var collection = [entry1, entry2, entry3];
                var referencedValues = {
                    human_id: ref1,
                    tags: ref2
                };

                collection = retrieveQueries.fillReferencesValuesFromCollection(collection, referencedValues, true);

                expect(collection.length).toEqual(3);
                expect(collection[0].listValues.human_id).toEqual('Bob');
                expect(collection[0].listValues.tags).toEqual(['Photo', 'Panda']);
                expect(collection[1].listValues.tags).toEqual(['Watch']);
                expect(collection[2].listValues.human_id).toEqual('Jack');
                expect(collection[2].listValues.tags).toEqual([]);
            });
            it('should return all references values for a View with one call', function (done) {
                var retrieveQueries = new RetrieveQueries($q, Restangular, config, PromisesResolver),
                    post = new Entity('posts'),
                    author = new Entity('authors'),
                    authorRef = new ReferenceField('author');

                authorRef.singleApiCall(function (ids) {
                    return {
                        id: ids
                    };
                });

                var rawPosts = [
                    {id: 1, author: 'abc'},
                    {id: 2, author: '19DFE'}
                ];

                var rawAuthors = [
                    {id: 'abc', name: 'Rollo'},
                    {id: '19DFE', name: 'Ragna'}
                ];

                var authors = [
                    new Entry('authors', rawAuthors[0]),
                    new Entry('authors', rawAuthors[1])
                ];

                authorRef.targetEntity(author);
                authorRef.targetField(new Field('name'));
                post.listView()
                    .addField(authorRef);

                spyOn(Restangular, 'getList').and.returnValue(mixins.buildPromise(mixins.buildPromise({})));
                spyOn(PromisesResolver, 'allEvenFailed').and.returnValue(mixins.buildPromise([{status: 'success', result: { data: rawAuthors }}]));

                retrieveQueries.getReferencedValues(post.listView().getReferences(), rawPosts)
                    .then(function (references) {
                        expect(references.author.entries.length).toEqual(2);
                        expect(references.author.entries[0].values.id).toEqual('abc');
                        expect(references.author.entries[1].values.name).toEqual('Ragna');
                    })
                    .then(done, done.fail);
            });