Created
May 30, 2014 19:10
-
-
Save lazarofl/b9b8bdf3547071f64249 to your computer and use it in GitHub Desktop.
$httpBackend para simular as requisições da app de lista de compras
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
var app = angular.module('app', []); | |
app.run(function($httpBackend){ | |
$httpBackend.whenGET('/listadecompras').respond( | |
[ { | |
nome: 'Pão', | |
quantidade: 2, | |
comprado: false | |
}, | |
{ | |
nome: 'Manteiga', | |
quantidade: 1, | |
comprado: false | |
}, | |
{ | |
nome: 'Leite', | |
quantidade: 1, | |
comprado: false | |
}, | |
{ | |
nome: 'Café', | |
quantidade: 2, | |
comprado: false | |
}, | |
{ | |
nome: 'Açúcar', | |
quantidade: 1, | |
comprado: false | |
} | |
] | |
); | |
this.newGuid = function () { | |
function s4() { | |
return Math.floor((1 + Math.random()) * 0x10000) | |
.toString(16) | |
.substring(1); | |
} | |
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + | |
s4() + '-' + s4() + s4() + s4(); | |
}; | |
$httpBackend.whenPOST('/listadecompras').respond(function(method, url, data){ | |
var json = angular.fromJson(data); | |
json.Id = newGuid(); | |
return [200, json]; | |
}); | |
$httpBackend.whenPUT('/listadecompras').respond(function(method, url, data){ | |
var json = angular.fromJson(data); | |
return [200, json]; | |
}); | |
$httpBackend.whenDELETE('/listadecompras').respond(function(method, url, data){ | |
return [200,{}]; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment