Sha256: b65965b22a950d1d00bee02b0c0fbd5e46e1439baf4df60291045629b4c08a7d

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

describe('root wrapping', function () {
    'use strict';

    beforeEach(module('rails'));

    var q, rootScope,
        transformer, interceptor,
        config = {config: {name: 'test', pluralName: 'tests'}};


    function testTransform(wrappedData, unwrappedData) {
        var result, resultPromise,
            deferred = q.defer();

        expect(transformer(unwrappedData, config)).toEqualData(wrappedData);
        deferred.promise.resource = config;
        expect(resultPromise = interceptor(deferred.promise)).toBeDefined();

        resultPromise.then(function (response) {
            result = response;
        });

        deferred.resolve({data: wrappedData});
        rootScope.$digest(); // needed for $q to actually run callbacks
        expect(result).toEqualData({data: unwrappedData});
    }

    beforeEach(inject(function ($rootScope, $q, railsRootWrappingTransformer, railsRootWrappingInterceptor) {
        q = $q;
        rootScope = $rootScope;
        transformer = railsRootWrappingTransformer;
        interceptor = railsRootWrappingInterceptor;
    }));

    it('should handle null root', function() {
        testTransform({test: null}, null);
    });

    it('should transform arrays', function() {
        testTransform({tests: [1, 2, 3]}, [1, 2, 3]);
    });

    it('should transform object', function() {
        testTransform({test: {abc: 'xyz', def: 'abc'}}, {abc: 'xyz', def: 'abc'});
    });
});

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
angularjs-rails-resource-1.0.0.pre.3 test/unit/angularjs/rails/rootWrappingSpec.js
angularjs-rails-resource-1.0.0.pre.2 test/unit/angularjs/rails/rootWrappingSpec.js
angularjs-rails-resource-1.0.0.pre.1 test/unit/angularjs/rails/rootWrappingSpec.js