Created
November 7, 2014 15:05
-
-
Save davidkpiano/09ca91f5dc506c80bb6a to your computer and use it in GitHub Desktop.
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
angular.module('App', ['Goats', 'ngMockE2E']) | |
.run(['$httpBackend', function($httpBackend) { | |
var goats = [{}]; | |
$httpBackend.whenGET(/views.*/).passThrough(); | |
$httpBackend.whenGET('/goats').respond(goats); | |
$httpBackend.whenGET(/goat\/.*/).respond(function(method, url, data) { | |
var name = url.split('/')[2]; | |
return [200, _.find(goats, {name: name})]; | |
}); | |
$httpBackend.whenGET(/\/goats\/search\/.*/) | |
.respond(function(method, url, data) { | |
var query = url.substr(14); | |
var result = _.filter(goats, function(goat) { | |
return _.contains((goat.name + goat.alt + goat.origin + goat.purpose).toUpperCase(), query.toUpperCase()); | |
}); | |
return [200, result]; | |
}); | |
$httpBackend.whenPOST('/goats').respond(function(method, url, data) { | |
data = angular.fromJson(data); | |
_.each(goats, function(goat, index) { | |
if (goat.name != data.name) return true; | |
_.extend(goats[index], data); | |
return false; | |
}); | |
return [200, goats, {}]; | |
}); | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment