Created
September 20, 2013 20:24
-
-
Save kasperlewau/6643347 to your computer and use it in GitHub Desktop.
Testing Restangular within a Controller.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.controller("GalleryCtrl", [ | |
'$scope', | |
'Restangular', | |
'$templateCache', | |
function($scope, Restangular, $templateCache) { | |
$scope.imgBase = Restangular.all('images'); | |
$scope.galleriesBase = Restangular.all('galleries'); | |
$scope.galleries = null; | |
$scope.getGalleries = function (active) { | |
$scope.galleriesBase.getList().then(function (g) { | |
$scope.galleries = g.reverse(); | |
$scope.setActiveGallery(active || _.first(g)); | |
}); | |
}; | |
$scope.setActiveGallery = function (x) { $scope.activeGallery = x; }; | |
$scope.getGalleries(); | |
}]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('GalleryCtrl', function () { | |
var $scope = null; | |
var ctrl = null; | |
var httpBackend; | |
var restangular; | |
function sanitizeRestangularAll(items) { | |
var all = _.map(items, function (item) { | |
return sanitizeRestangularOne(item); | |
}); | |
return sanitizeRestangularOne(all); | |
} | |
function sanitizeRestangularOne(item) { | |
return _.omit(item, "route", "parentResource", "getList", "get", "post", "put", "remove", "head", "trace", "options", "patch", | |
"$get", "$save", "$query", "$remove", "$delete", "$put", "$post", "$head", "$trace", "$options", "$patch", | |
"$then", "$resolved", "restangularCollection", "customOperation", "customGET", "customPOST", | |
"customPUT", "customDELETE", "customGETLIST", "$getList", "$resolved", "restangularCollection", "one", "all", "doGET", "doPOST", | |
"doPUT", "doDELETE", "doGETLIST", "addRestangularMethod", "getRestangularUrl"); | |
} | |
existence = function(input) { | |
expect(input).not.toBeNull(); | |
expect(input).toBeDefined(); | |
}; | |
beforeEach(module('app')); | |
beforeEach(module('restangular')); | |
beforeEach(inject(function($controller, _$httpBackend_, $rootScope, _Restangular_) { | |