22/**
33 * @author Jason Dobry <[email protected] > 44 * @file angular-data-mocks.js
5- * @version 0.5.5 - Homepage <https://github.com/jmdobry/angular-data-mocks>
5+ * @version 0.6.0 - Homepage <https://github.com/jmdobry/angular-data-mocks>
66 * @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
77 * @license MIT <https://github.com/jmdobry/angular-data-mocks/blob/master/LICENSE>
88 *
@@ -739,8 +739,9 @@ function DSProvider() {
739739 'bindAll' ,
740740 'bindOne' ,
741741 'changes' ,
742- 'defineResource ' ,
742+ 'compute ' ,
743743 'createInstance' ,
744+ 'defineResource' ,
744745 'digest' ,
745746 'eject' ,
746747 'ejectAll' ,
@@ -750,13 +751,17 @@ function DSProvider() {
750751 'inject' ,
751752 'lastModified' ,
752753 'lastSaved' ,
754+ 'link' ,
755+ 'linkAll' ,
756+ 'linkInverse' ,
753757 'previous'
754758 ] ;
755759
756760 var methodsToProxy = [
757761 'bindAll' ,
758762 'bindOne' ,
759763 'changes' ,
764+ 'compute' ,
760765 'create' ,
761766 'createInstance' ,
762767 'destroy' ,
@@ -771,6 +776,9 @@ function DSProvider() {
771776 'inject' ,
772777 'lastModified' ,
773778 'lastSaved' ,
779+ 'link' ,
780+ 'linkAll' ,
781+ 'linkInverse' ,
774782 'loadRelations' ,
775783 'previous' ,
776784 'refresh' ,
@@ -1278,7 +1286,7 @@ module.exports = DSProvider;
12781286 * @description
12791287 * Fake angular-data implementation suitable for unit testing angular applications that use the `angular-data.DS` module.
12801288 *
1281- * __Version:__ 0.5.5
1289+ * __Version:__ 0.6.0
12821290 *
12831291 * __angular-data-mocks requires SinonJS to be loaded in order to work.__
12841292 *
@@ -1311,134 +1319,135 @@ module.exports = DSProvider;
13111319( function ( window , angular , undefined ) {
13121320 'use strict' ;
13131321
1314- function prettyPrint ( data ) {
1315- return ( angular . isString ( data ) || angular . isFunction ( data ) ) ? data : angular . toJson ( data ) ;
1316- }
1317-
1318- function createResponse ( resource , deferred , response ) {
1319- return function respond ( ) {
1320- if ( ! ( response [ 0 ] instanceof Error ) ) {
1321- deferred . resolve . apply ( null , response ) ;
1322- } else {
1323- deferred . reject . apply ( null , response ) ;
1324- }
1325- } ;
1326- }
1327-
1328- function mockAsync ( name , namespace , expectations , definitions , requests , responses ) {
1329- return function ( ) {
1330- var args = Array . prototype . slice . call ( arguments ) ;
1331- var expectation = expectations [ 0 ] ;
1332- var deferred = $q . defer ( ) ;
1333- var resourceName = args [ 0 ] ;
1334-
1335- if ( expectation && expectation . match ( name , resourceName ) ) {
1336- expectations . shift ( ) ;
1337-
1338- if ( ! expectation . matchArgs ( args ) ) {
1339- throw new Error ( 'Expected ' + expectation + ' with different args\n' +
1340- 'EXPECTED: ' + prettyPrint ( expectation . args ) + '\nGOT: ' + prettyPrint ( args ) ) ;
1341- }
1322+ angular . module ( 'angular-data.mock-utils' , [ 'angular-data.DS' , 'ng' ] )
1323+ . service ( 'DSMockUtils' , [ '$q' , function ( $q ) {
13421324
1343- if ( expectation . response ) {
1344- responses . push ( createResponse ( resourceName , deferred , expectation . response ) ) ;
1345- return deferred . promise ;
1346- } else {
1347- throw new Error ( 'No response defined for ' + namespace + '.' + expectation . method ) ;
1348- }
1325+ function prettyPrint ( data ) {
1326+ return ( angular . isString ( data ) || angular . isFunction ( data ) ) ? data : angular . toJson ( data ) ;
13491327 }
13501328
1351- // try to match request to any backend definitions
1352- for ( var i = 0 ; i < definitions . length ; i ++ ) {
1353- var definition = definitions [ i ] ;
1354-
1355- if ( definition . match ( name , resourceName ) ) {
1356- if ( definition . response ) {
1357- responses . push ( createResponse ( resourceName , deferred , definition . response ) ) ;
1358- return deferred . promise ;
1329+ function createResponse ( resource , deferred , response ) {
1330+ return function respond ( ) {
1331+ if ( ! ( response [ 0 ] instanceof Error ) ) {
1332+ deferred . resolve . apply ( null , response ) ;
13591333 } else {
1360- throw new Error ( 'No response defined !' ) ;
1334+ deferred . reject . apply ( null , response ) ;
13611335 }
1362- }
1336+ } ;
13631337 }
13641338
1365- // Any requests that made it this far aren't being handled, so throw an exception
1366- throw new Error ( 'Unexpected request: ' + namespace + '.' + name + ' ' + resourceName + '\n' +
1367- 'No more requests expected' ) ;
1368- } ;
1369- }
1339+ function mockAsync ( name , namespace , expectations , definitions , requests , responses ) {
1340+ return function ( ) {
1341+ var args = Array . prototype . slice . call ( arguments ) ;
1342+ var expectation = expectations [ 0 ] ;
1343+ var deferred = $q . defer ( ) ;
1344+ var resourceName = args [ 0 ] ;
1345+
1346+ if ( expectation && expectation . match ( name , resourceName ) ) {
1347+ expectations . shift ( ) ;
1348+
1349+ if ( ! expectation . matchArgs ( args ) ) {
1350+ throw new Error ( 'Expected ' + expectation + ' with different args\n' +
1351+ 'EXPECTED: ' + prettyPrint ( expectation . args ) + '\nGOT: ' + prettyPrint ( args ) ) ;
1352+ }
1353+
1354+ if ( expectation . response ) {
1355+ responses . push ( createResponse ( resourceName , deferred , expectation . response ) ) ;
1356+ return deferred . promise ;
1357+ } else {
1358+ throw new Error ( 'No response defined for ' + namespace + '.' + expectation . method ) ;
1359+ }
1360+ }
13701361
1371- function createShortMethod ( name , expectations ) {
1372- return function ( ) {
1373- var args = Array . prototype . slice . call ( arguments ) ;
1374- if ( args [ 0 ] === undefined ) {
1375- throw new Error ( 'Resource not defined for expectation!' ) ;
1362+ // try to match request to any backend definitions
1363+ for ( var i = 0 ; i < definitions . length ; i ++ ) {
1364+ var definition = definitions [ i ] ;
1365+
1366+ if ( definition . match ( name , resourceName ) ) {
1367+ if ( definition . response ) {
1368+ responses . push ( createResponse ( resourceName , deferred , definition . response ) ) ;
1369+ return deferred . promise ;
1370+ } else {
1371+ throw new Error ( 'No response defined !' ) ;
1372+ }
1373+ }
1374+ }
1375+
1376+ // Any requests that made it this far aren't being handled, so throw an exception
1377+ throw new Error ( 'Unexpected request: ' + namespace + '.' + name + ' ' + resourceName + '\n' +
1378+ 'No more requests expected' ) ;
1379+ } ;
13761380 }
1377- var expectation = new MockDSExpectation ( name , args ) ;
1378- expectations . push ( expectation ) ;
13791381
1380- return {
1381- respond : function ( ) {
1382- expectation . response = Array . prototype . slice . call ( arguments ) ;
1383- }
1384- } ;
1385- } ;
1386- }
1382+ function createShortMethod ( name , expectations ) {
1383+ return function ( ) {
1384+ var args = Array . prototype . slice . call ( arguments ) ;
1385+ if ( args [ 0 ] === undefined ) {
1386+ throw new Error ( 'Resource not defined for expectation!' ) ;
1387+ }
1388+ var expectation = new MockDSExpectation ( name , args ) ;
1389+ expectations . push ( expectation ) ;
1390+
1391+ return {
1392+ respond : function ( ) {
1393+ expectation . response = Array . prototype . slice . call ( arguments ) ;
1394+ }
1395+ } ;
1396+ } ;
1397+ }
13871398
1388- function MockDSExpectation ( method , args ) {
1389- this . method = method ;
1390- this . args = args ;
1391- this . resourceName = this . args [ 0 ] ;
1399+ function MockDSExpectation ( method , args ) {
1400+ this . method = method ;
1401+ this . args = args ;
1402+ this . resourceName = this . args [ 0 ] ;
13921403
1393- this . match = function ( m , resourceName ) {
1394- if ( method !== m ) {
1395- return false ;
1396- } else if ( this . resourceName !== resourceName ) {
1397- return false ;
1398- }
1399- return true ;
1400- } ;
1404+ this . match = function ( m , resourceName ) {
1405+ if ( method !== m ) {
1406+ return false ;
1407+ } else if ( this . resourceName !== resourceName ) {
1408+ return false ;
1409+ }
1410+ return true ;
1411+ } ;
14011412
1402- this . matchArgs = function ( a ) {
1403- if ( this . args . length === 0 ) {
1404- return true ;
1405- }
1413+ this . matchArgs = function ( a ) {
1414+ if ( this . args . length === 0 ) {
1415+ return true ;
1416+ }
14061417
1407- var isEqual = false ;
1408- for ( var i = 0 ; i < this . args . length ; i ++ ) {
1409- isEqual = angular . equals ( this . args [ i ] , a [ i ] ) ;
1410- if ( ! isEqual ) {
1411- break ;
1412- }
1418+ var isEqual = false ;
1419+ for ( var i = 0 ; i < this . args . length ; i ++ ) {
1420+ isEqual = angular . equals ( this . args [ i ] , a [ i ] ) ;
1421+ if ( ! isEqual ) {
1422+ break ;
1423+ }
1424+ }
1425+ return isEqual ;
1426+ } ;
14131427 }
1414- return isEqual ;
1415- } ;
1416- }
14171428
1418- function MockDSAdapterExpectation ( method , args ) {
1419- this . method = method ;
1420- this . args = args ;
1421- this . match = function ( m ) {
1422- return method === m ;
1423- } ;
1424- this . matchArgs = function ( a ) {
1425- if ( this . args . length === 0 ) {
1426- return true ;
1427- }
1429+ function MockDSAdapterExpectation ( method , args ) {
1430+ this . method = method ;
1431+ this . args = args ;
1432+ this . match = function ( m ) {
1433+ return method === m ;
1434+ } ;
1435+ this . matchArgs = function ( a ) {
1436+ if ( this . args . length === 0 ) {
1437+ return true ;
1438+ }
14281439
1429- var isEqual = false ;
1430- for ( var i = 0 ; i < this . args . length ; i ++ ) {
1431- isEqual = angular . equals ( this . args [ i ] , a [ i ] ) ;
1432- if ( ! isEqual ) {
1433- break ;
1434- }
1440+ var isEqual = false ;
1441+ for ( var i = 0 ; i < this . args . length ; i ++ ) {
1442+ isEqual = angular . equals ( this . args [ i ] , a [ i ] ) ;
1443+ if ( ! isEqual ) {
1444+ break ;
1445+ }
1446+ }
1447+ return isEqual ;
1448+ } ;
14351449 }
1436- return isEqual ;
1437- } ;
1438- }
14391450
1440- angular . module ( 'angular-data.mock-utils' , [ 'angular-data.DS' , 'ng' ] )
1441- . service ( 'DSMockUtils' , [ function ( ) {
14421451 return {
14431452 prettyPrint : prettyPrint ,
14441453 createResponse : createResponse ,
@@ -1463,7 +1472,7 @@ module.exports = DSProvider;
14631472 'angular-data.DSHttpAdapterMock' ,
14641473 'angular-data.DSLocalStorageAdapterMock'
14651474 ] )
1466- . value ( 'version' , '0.5.5 ' ) ;
1475+ . value ( 'version' , '0.6.0 ' ) ;
14671476
14681477} ) ( window , window . angular ) ;
14691478
0 commit comments