11// Setup global test variables
2- var $rootScope , $q , $log , DS , app , $httpBackend , p1 , p2 , p3 , p4 ;
2+ var $rootScope , $q , $log , DSProvider , DS , app , $httpBackend , p1 , p2 , p3 , p4 ;
3+
4+ var lifecycle = { } ;
35
46// Helper globals
57var fail = function ( msg ) {
@@ -27,20 +29,66 @@ angular.module('app', ['ng', 'jmdobry.angular-data']);
2729
2830// Setup before each test
2931beforeEach ( function ( done ) {
30- module ( 'app' ) ;
32+ lifecycle . beforeValidate = function ( resourceName , attrs , cb ) {
33+ lifecycle . beforeValidate . callCount += 1 ;
34+ cb ( null , attrs ) ;
35+ } ;
36+ lifecycle . validate = function ( resourceName , attrs , cb ) {
37+ lifecycle . validate . callCount += 1 ;
38+ cb ( null , attrs ) ;
39+ } ;
40+ lifecycle . afterValidate = function ( resourceName , attrs , cb ) {
41+ lifecycle . afterValidate . callCount += 1 ;
42+ cb ( null , attrs ) ;
43+ } ;
44+ lifecycle . beforeCreate = function ( resourceName , attrs , cb ) {
45+ lifecycle . beforeCreate . callCount += 1 ;
46+ cb ( null , attrs ) ;
47+ } ;
48+ lifecycle . afterCreate = function ( resourceName , attrs , cb ) {
49+ lifecycle . afterCreate . callCount += 1 ;
50+ cb ( null , attrs ) ;
51+ } ;
52+ lifecycle . beforeUpdate = function ( resourceName , attrs , cb ) {
53+ lifecycle . beforeUpdate . callCount += 1 ;
54+ cb ( null , attrs ) ;
55+ } ;
56+ lifecycle . afterUpdate = function ( resourceName , attrs , cb ) {
57+ lifecycle . afterUpdate . callCount += 1 ;
58+ cb ( null , attrs ) ;
59+ } ;
60+ lifecycle . beforeDestroy = function ( resourceName , attrs , cb ) {
61+ lifecycle . beforeDestroy . callCount += 1 ;
62+ cb ( null , attrs ) ;
63+ } ;
64+ lifecycle . afterDestroy = function ( resourceName , attrs , cb ) {
65+ lifecycle . afterDestroy . callCount += 1 ;
66+ cb ( null , attrs ) ;
67+ } ;
68+ module ( 'app' , function ( _DSProvider_ ) {
69+ DSProvider = _DSProvider_ ;
70+ DSProvider . config ( {
71+ baseUrl : 'http://test.angular-cache.com' ,
72+ beforeValidate : lifecycle . beforeValidate ,
73+ validate : lifecycle . validate ,
74+ afterValidate : lifecycle . afterValidate ,
75+ beforeCreate : lifecycle . beforeCreate ,
76+ afterCreate : lifecycle . afterCreate ,
77+ beforeUpdate : lifecycle . beforeUpdate ,
78+ afterUpdate : lifecycle . afterUpdate ,
79+ beforeDestroy : lifecycle . beforeDestroy ,
80+ afterDestroy : lifecycle . afterDestroy
81+ } ) ;
82+ } ) ;
3183 inject ( function ( _$rootScope_ , _$q_ , _$httpBackend_ , _DS_ ) {
3284 // Setup global mocks
3385 $q = _$q_ ;
3486 $rootScope = _$rootScope_ ;
3587 DS = _DS_ ;
3688 $httpBackend = _$httpBackend_ ;
37- app = {
38- baseUrl : 'http://test.angular-cache.com'
39- } ;
4089 DS . defineResource ( {
4190 name : 'post' ,
42- endpoint : '/posts' ,
43- baseUrl : app . baseUrl
91+ endpoint : '/posts'
4492 } ) ;
4593 $log = {
4694 warn : function ( ) {
@@ -61,6 +109,16 @@ beforeEach(function (done) {
61109 sinon . spy ( $log , 'info' ) ;
62110 sinon . spy ( $log , 'error' ) ;
63111 sinon . spy ( $log , 'debug' ) ;
112+
113+ lifecycle . beforeValidate . callCount = 0 ;
114+ lifecycle . validate . callCount = 0 ;
115+ lifecycle . afterValidate . callCount = 0 ;
116+ lifecycle . beforeCreate . callCount = 0 ;
117+ lifecycle . afterCreate . callCount = 0 ;
118+ lifecycle . beforeUpdate . callCount = 0 ;
119+ lifecycle . afterUpdate . callCount = 0 ;
120+ lifecycle . beforeDestroy . callCount = 0 ;
121+ lifecycle . afterDestroy . callCount = 0 ;
64122 } ) ;
65123
66124 p1 = { author : 'John' , age : 30 , id : 5 } ;
@@ -79,6 +137,7 @@ afterEach(function () {
79137 $log . info . restore ( ) ;
80138 $log . error . restore ( ) ;
81139 $log . debug . restore ( ) ;
140+
82141 $httpBackend . verifyNoOutstandingExpectation ( ) ;
83142 $httpBackend . verifyNoOutstandingRequest ( ) ;
84143} ) ;
0 commit comments