angularjs-rails 1.2.26 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/angularjs-rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/angular-animate.js +879 -456
  4. data/vendor/assets/javascripts/angular-aria.js +250 -0
  5. data/vendor/assets/javascripts/angular-cookies.js +1 -1
  6. data/vendor/assets/javascripts/angular-loader.js +17 -10
  7. data/vendor/assets/javascripts/angular-messages.js +400 -0
  8. data/vendor/assets/javascripts/angular-mocks.js +220 -110
  9. data/vendor/assets/javascripts/angular-resource.js +287 -247
  10. data/vendor/assets/javascripts/angular-route.js +111 -54
  11. data/vendor/assets/javascripts/angular-sanitize.js +1 -1
  12. data/vendor/assets/javascripts/angular-scenario.js +11579 -8665
  13. data/vendor/assets/javascripts/angular-touch.js +49 -11
  14. data/vendor/assets/javascripts/angular.js +6660 -3106
  15. data/vendor/assets/javascripts/unstable/angular-animate.js +240 -71
  16. data/vendor/assets/javascripts/unstable/angular-aria.js +12 -12
  17. data/vendor/assets/javascripts/unstable/angular-cookies.js +1 -1
  18. data/vendor/assets/javascripts/unstable/angular-loader.js +4 -4
  19. data/vendor/assets/javascripts/unstable/angular-messages.js +1 -1
  20. data/vendor/assets/javascripts/unstable/angular-mocks.js +21 -14
  21. data/vendor/assets/javascripts/unstable/angular-resource.js +2 -2
  22. data/vendor/assets/javascripts/unstable/angular-route.js +1 -1
  23. data/vendor/assets/javascripts/unstable/angular-sanitize.js +1 -1
  24. data/vendor/assets/javascripts/unstable/angular-scenario.js +562 -262
  25. data/vendor/assets/javascripts/unstable/angular-touch.js +1 -1
  26. data/vendor/assets/javascripts/unstable/angular.js +562 -262
  27. metadata +16 -14
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license AngularJS v1.2.26
2
+ * @license AngularJS v1.3.0
3
3
  * (c) 2010-2014 Google, Inc. http://angularjs.org
4
4
  * License: MIT
5
5
  */
@@ -53,9 +53,10 @@ angular.mock.$Browser = function() {
53
53
  self.onUrlChange = function(listener) {
54
54
  self.pollFns.push(
55
55
  function() {
56
- if (self.$$lastUrl != self.$$url) {
56
+ if (self.$$lastUrl !== self.$$url || self.$$state !== self.$$lastState) {
57
57
  self.$$lastUrl = self.$$url;
58
- listener(self.$$url);
58
+ self.$$lastState = self.$$state;
59
+ listener(self.$$url, self.$$state);
59
60
  }
60
61
  }
61
62
  );
@@ -127,7 +128,7 @@ angular.mock.$Browser = function() {
127
128
  }
128
129
  };
129
130
 
130
- self.$$baseHref = '';
131
+ self.$$baseHref = '/';
131
132
  self.baseHref = function() {
132
133
  return this.$$baseHref;
133
134
  };
@@ -151,15 +152,24 @@ angular.mock.$Browser.prototype = {
151
152
  return pollFn;
152
153
  },
153
154
 
154
- url: function(url, replace) {
155
+ url: function(url, replace, state) {
156
+ if (angular.isUndefined(state)) {
157
+ state = null;
158
+ }
155
159
  if (url) {
156
160
  this.$$url = url;
161
+ // Native pushState serializes & copies the object; simulate it.
162
+ this.$$state = angular.copy(state);
157
163
  return this;
158
164
  }
159
165
 
160
166
  return this.$$url;
161
167
  },
162
168
 
169
+ state: function() {
170
+ return this.$$state;
171
+ },
172
+
163
173
  cookies: function(name, value) {
164
174
  if (name) {
165
175
  if (angular.isUndefined(value)) {
@@ -191,7 +201,7 @@ angular.mock.$Browser.prototype = {
191
201
  *
192
202
  * @description
193
203
  * Configures the mock implementation of {@link ng.$exceptionHandler} to rethrow or to log errors
194
- * passed into the `$exceptionHandler`.
204
+ * passed to the `$exceptionHandler`.
195
205
  */
196
206
 
197
207
  /**
@@ -200,7 +210,7 @@ angular.mock.$Browser.prototype = {
200
210
  *
201
211
  * @description
202
212
  * Mock implementation of {@link ng.$exceptionHandler} that rethrows or logs errors passed
203
- * into it. See {@link ngMock.$exceptionHandlerProvider $exceptionHandlerProvider} for configuration
213
+ * to it. See {@link ngMock.$exceptionHandlerProvider $exceptionHandlerProvider} for configuration
204
214
  * information.
205
215
  *
206
216
  *
@@ -240,9 +250,8 @@ angular.mock.$ExceptionHandlerProvider = function() {
240
250
  *
241
251
  * @param {string} mode Mode of operation, defaults to `rethrow`.
242
252
  *
243
- * - `rethrow`: If any errors are passed into the handler in tests, it typically
244
- * means that there is a bug in the application or test, so this mock will
245
- * make these tests fail.
253
+ * - `rethrow`: If any errors are passed to the handler in tests, it typically means that there
254
+ * is a bug in the application or test, so this mock will make these tests fail.
246
255
  * - `log`: Sometimes it is desirable to test that an error is thrown, for this case the `log`
247
256
  * mode stores an array of errors in `$exceptionHandler.errors`, to allow later
248
257
  * assertion of them. See {@link ngMock.$log#assertEmpty assertEmpty()} and
@@ -333,7 +342,7 @@ angular.mock.$LogProvider = function() {
333
342
  * @name $log#log.logs
334
343
  *
335
344
  * @description
336
- * Array of messages logged using {@link ngMock.$log#log}.
345
+ * Array of messages logged using {@link ng.$log#log `log()`}.
337
346
  *
338
347
  * @example
339
348
  * ```js
@@ -347,7 +356,7 @@ angular.mock.$LogProvider = function() {
347
356
  * @name $log#info.logs
348
357
  *
349
358
  * @description
350
- * Array of messages logged using {@link ngMock.$log#info}.
359
+ * Array of messages logged using {@link ng.$log#info `info()`}.
351
360
  *
352
361
  * @example
353
362
  * ```js
@@ -361,7 +370,7 @@ angular.mock.$LogProvider = function() {
361
370
  * @name $log#warn.logs
362
371
  *
363
372
  * @description
364
- * Array of messages logged using {@link ngMock.$log#warn}.
373
+ * Array of messages logged using {@link ng.$log#warn `warn()`}.
365
374
  *
366
375
  * @example
367
376
  * ```js
@@ -375,7 +384,7 @@ angular.mock.$LogProvider = function() {
375
384
  * @name $log#error.logs
376
385
  *
377
386
  * @description
378
- * Array of messages logged using {@link ngMock.$log#error}.
387
+ * Array of messages logged using {@link ng.$log#error `error()`}.
379
388
  *
380
389
  * @example
381
390
  * ```js
@@ -389,7 +398,7 @@ angular.mock.$LogProvider = function() {
389
398
  * @name $log#debug.logs
390
399
  *
391
400
  * @description
392
- * Array of messages logged using {@link ngMock.$log#debug}.
401
+ * Array of messages logged using {@link ng.$log#debug `debug()`}.
393
402
  *
394
403
  * @example
395
404
  * ```js
@@ -405,8 +414,8 @@ angular.mock.$LogProvider = function() {
405
414
  * @name $log#assertEmpty
406
415
  *
407
416
  * @description
408
- * Assert that the all of the logging methods have no logged messages. If messages present, an
409
- * exception is thrown.
417
+ * Assert that all of the logging methods have no logged messages. If any messages are present,
418
+ * an exception is thrown.
410
419
  */
411
420
  $log.assertEmpty = function() {
412
421
  var errors = [];
@@ -776,13 +785,22 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
776
785
  };
777
786
  });
778
787
 
779
- $provide.decorator('$animate', function($delegate, $$asyncCallback) {
788
+ $provide.decorator('$animate', ['$delegate', '$$asyncCallback', '$timeout', '$browser',
789
+ function($delegate, $$asyncCallback, $timeout, $browser) {
780
790
  var animate = {
781
791
  queue : [],
792
+ cancel : $delegate.cancel,
782
793
  enabled : $delegate.enabled,
783
- triggerCallbacks : function() {
794
+ triggerCallbackEvents : function() {
784
795
  $$asyncCallback.flush();
785
796
  },
797
+ triggerCallbackPromise : function() {
798
+ $timeout.flush(0);
799
+ },
800
+ triggerCallbacks : function() {
801
+ this.triggerCallbackEvents();
802
+ this.triggerCallbackPromise();
803
+ },
786
804
  triggerReflow : function() {
787
805
  angular.forEach(reflowQueue, function(fn) {
788
806
  fn();
@@ -792,19 +810,20 @@ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
792
810
  };
793
811
 
794
812
  angular.forEach(
795
- ['enter','leave','move','addClass','removeClass','setClass'], function(method) {
813
+ ['animate','enter','leave','move','addClass','removeClass','setClass'], function(method) {
796
814
  animate[method] = function() {
797
815
  animate.queue.push({
798
816
  event : method,
799
817
  element : arguments[0],
818
+ options : arguments[arguments.length-1],
800
819
  args : arguments
801
820
  });
802
- $delegate[method].apply($delegate, arguments);
821
+ return $delegate[method].apply($delegate, arguments);
803
822
  };
804
823
  });
805
824
 
806
825
  return animate;
807
- });
826
+ }]);
808
827
 
809
828
  }]);
810
829
 
@@ -982,6 +1001,11 @@ angular.mock.dump = function(object) {
982
1001
  * First we create the controller under test:
983
1002
  *
984
1003
  ```js
1004
+ // The module code
1005
+ angular
1006
+ .module('MyApp', [])
1007
+ .controller('MyController', MyController);
1008
+
985
1009
  // The controller code
986
1010
  function MyController($scope, $http) {
987
1011
  var authToken;
@@ -1009,13 +1033,17 @@ angular.mock.dump = function(object) {
1009
1033
  ```js
1010
1034
  // testing controller
1011
1035
  describe('MyController', function() {
1012
- var $httpBackend, $rootScope, createController;
1036
+ var $httpBackend, $rootScope, createController, authRequestHandler;
1037
+
1038
+ // Set up the module
1039
+ beforeEach(module('MyApp'));
1013
1040
 
1014
1041
  beforeEach(inject(function($injector) {
1015
1042
  // Set up the mock http service responses
1016
1043
  $httpBackend = $injector.get('$httpBackend');
1017
1044
  // backend definition common for all tests
1018
- $httpBackend.when('GET', '/auth.py').respond({userId: 'userX'}, {'A-Token': 'xxx'});
1045
+ authRequestHandler = $httpBackend.when('GET', '/auth.py')
1046
+ .respond({userId: 'userX'}, {'A-Token': 'xxx'});
1019
1047
 
1020
1048
  // Get hold of a scope (i.e. the root scope)
1021
1049
  $rootScope = $injector.get('$rootScope');
@@ -1041,6 +1069,18 @@ angular.mock.dump = function(object) {
1041
1069
  });
1042
1070
 
1043
1071
 
1072
+ it('should fail authentication', function() {
1073
+
1074
+ // Notice how you can change the response even after it was set
1075
+ authRequestHandler.respond(401, '');
1076
+
1077
+ $httpBackend.expectGET('/auth.py');
1078
+ var controller = createController();
1079
+ $httpBackend.flush();
1080
+ expect($rootScope.status).toBe('Failed...');
1081
+ });
1082
+
1083
+
1044
1084
  it('should send msg to server', function() {
1045
1085
  var controller = createController();
1046
1086
  $httpBackend.flush();
@@ -1188,32 +1228,39 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1188
1228
  * Creates a new backend definition.
1189
1229
  *
1190
1230
  * @param {string} method HTTP method.
1191
- * @param {string|RegExp} url HTTP url.
1231
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1232
+ * and returns true if the url match the current definition.
1192
1233
  * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives
1193
1234
  * data string and returns true if the data is as expected.
1194
1235
  * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
1195
1236
  * object and returns true if the headers match the current definition.
1196
1237
  * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1197
- * request is handled.
1238
+ * request is handled. You can save this object for later use and invoke `respond` again in
1239
+ * order to change how a matched request is handled.
1198
1240
  *
1199
1241
  * - respond –
1200
1242
  * `{function([status,] data[, headers, statusText])
1201
1243
  * | function(function(method, url, data, headers)}`
1202
1244
  * – The respond method takes a set of static data to be returned or a function that can
1203
1245
  * return an array containing response status (number), response data (string), response
1204
- * headers (Object), and the text for the status (string).
1246
+ * headers (Object), and the text for the status (string). The respond method returns the
1247
+ * `requestHandler` object for possible overrides.
1205
1248
  */
1206
1249
  $httpBackend.when = function(method, url, data, headers) {
1207
1250
  var definition = new MockHttpExpectation(method, url, data, headers),
1208
1251
  chain = {
1209
1252
  respond: function(status, data, headers, statusText) {
1253
+ definition.passThrough = undefined;
1210
1254
  definition.response = createResponse(status, data, headers, statusText);
1255
+ return chain;
1211
1256
  }
1212
1257
  };
1213
1258
 
1214
1259
  if ($browser) {
1215
1260
  chain.passThrough = function() {
1261
+ definition.response = undefined;
1216
1262
  definition.passThrough = true;
1263
+ return chain;
1217
1264
  };
1218
1265
  }
1219
1266
 
@@ -1227,10 +1274,12 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1227
1274
  * @description
1228
1275
  * Creates a new backend definition for GET requests. For more info see `when()`.
1229
1276
  *
1230
- * @param {string|RegExp} url HTTP url.
1277
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1278
+ * and returns true if the url match the current definition.
1231
1279
  * @param {(Object|function(Object))=} headers HTTP headers.
1232
1280
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1233
- * request is handled.
1281
+ * request is handled. You can save this object for later use and invoke `respond` again in
1282
+ * order to change how a matched request is handled.
1234
1283
  */
1235
1284
 
1236
1285
  /**
@@ -1239,10 +1288,12 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1239
1288
  * @description
1240
1289
  * Creates a new backend definition for HEAD requests. For more info see `when()`.
1241
1290
  *
1242
- * @param {string|RegExp} url HTTP url.
1291
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1292
+ * and returns true if the url match the current definition.
1243
1293
  * @param {(Object|function(Object))=} headers HTTP headers.
1244
1294
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1245
- * request is handled.
1295
+ * request is handled. You can save this object for later use and invoke `respond` again in
1296
+ * order to change how a matched request is handled.
1246
1297
  */
1247
1298
 
1248
1299
  /**
@@ -1251,10 +1302,12 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1251
1302
  * @description
1252
1303
  * Creates a new backend definition for DELETE requests. For more info see `when()`.
1253
1304
  *
1254
- * @param {string|RegExp} url HTTP url.
1305
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1306
+ * and returns true if the url match the current definition.
1255
1307
  * @param {(Object|function(Object))=} headers HTTP headers.
1256
1308
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1257
- * request is handled.
1309
+ * request is handled. You can save this object for later use and invoke `respond` again in
1310
+ * order to change how a matched request is handled.
1258
1311
  */
1259
1312
 
1260
1313
  /**
@@ -1263,12 +1316,14 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1263
1316
  * @description
1264
1317
  * Creates a new backend definition for POST requests. For more info see `when()`.
1265
1318
  *
1266
- * @param {string|RegExp} url HTTP url.
1319
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1320
+ * and returns true if the url match the current definition.
1267
1321
  * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives
1268
1322
  * data string and returns true if the data is as expected.
1269
1323
  * @param {(Object|function(Object))=} headers HTTP headers.
1270
1324
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1271
- * request is handled.
1325
+ * request is handled. You can save this object for later use and invoke `respond` again in
1326
+ * order to change how a matched request is handled.
1272
1327
  */
1273
1328
 
1274
1329
  /**
@@ -1277,12 +1332,14 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1277
1332
  * @description
1278
1333
  * Creates a new backend definition for PUT requests. For more info see `when()`.
1279
1334
  *
1280
- * @param {string|RegExp} url HTTP url.
1335
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1336
+ * and returns true if the url match the current definition.
1281
1337
  * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives
1282
1338
  * data string and returns true if the data is as expected.
1283
1339
  * @param {(Object|function(Object))=} headers HTTP headers.
1284
1340
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1285
- * request is handled.
1341
+ * request is handled. You can save this object for later use and invoke `respond` again in
1342
+ * order to change how a matched request is handled.
1286
1343
  */
1287
1344
 
1288
1345
  /**
@@ -1291,9 +1348,11 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1291
1348
  * @description
1292
1349
  * Creates a new backend definition for JSONP requests. For more info see `when()`.
1293
1350
  *
1294
- * @param {string|RegExp} url HTTP url.
1351
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1352
+ * and returns true if the url match the current definition.
1295
1353
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1296
- * request is handled.
1354
+ * request is handled. You can save this object for later use and invoke `respond` again in
1355
+ * order to change how a matched request is handled.
1297
1356
  */
1298
1357
  createShortMethods('when');
1299
1358
 
@@ -1305,30 +1364,36 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1305
1364
  * Creates a new request expectation.
1306
1365
  *
1307
1366
  * @param {string} method HTTP method.
1308
- * @param {string|RegExp} url HTTP url.
1367
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1368
+ * and returns true if the url match the current definition.
1309
1369
  * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1310
1370
  * receives data string and returns true if the data is as expected, or Object if request body
1311
1371
  * is in JSON format.
1312
1372
  * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
1313
1373
  * object and returns true if the headers match the current expectation.
1314
1374
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1315
- * request is handled.
1375
+ * request is handled. You can save this object for later use and invoke `respond` again in
1376
+ * order to change how a matched request is handled.
1316
1377
  *
1317
1378
  * - respond –
1318
1379
  * `{function([status,] data[, headers, statusText])
1319
1380
  * | function(function(method, url, data, headers)}`
1320
1381
  * – The respond method takes a set of static data to be returned or a function that can
1321
1382
  * return an array containing response status (number), response data (string), response
1322
- * headers (Object), and the text for the status (string).
1383
+ * headers (Object), and the text for the status (string). The respond method returns the
1384
+ * `requestHandler` object for possible overrides.
1323
1385
  */
1324
1386
  $httpBackend.expect = function(method, url, data, headers) {
1325
- var expectation = new MockHttpExpectation(method, url, data, headers);
1387
+ var expectation = new MockHttpExpectation(method, url, data, headers),
1388
+ chain = {
1389
+ respond: function (status, data, headers, statusText) {
1390
+ expectation.response = createResponse(status, data, headers, statusText);
1391
+ return chain;
1392
+ }
1393
+ };
1394
+
1326
1395
  expectations.push(expectation);
1327
- return {
1328
- respond: function (status, data, headers, statusText) {
1329
- expectation.response = createResponse(status, data, headers, statusText);
1330
- }
1331
- };
1396
+ return chain;
1332
1397
  };
1333
1398
 
1334
1399
 
@@ -1338,10 +1403,12 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1338
1403
  * @description
1339
1404
  * Creates a new request expectation for GET requests. For more info see `expect()`.
1340
1405
  *
1341
- * @param {string|RegExp} url HTTP url.
1406
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1407
+ * and returns true if the url match the current definition.
1342
1408
  * @param {Object=} headers HTTP headers.
1343
1409
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1344
- * request is handled. See #expect for more info.
1410
+ * request is handled. You can save this object for later use and invoke `respond` again in
1411
+ * order to change how a matched request is handled. See #expect for more info.
1345
1412
  */
1346
1413
 
1347
1414
  /**
@@ -1350,10 +1417,12 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1350
1417
  * @description
1351
1418
  * Creates a new request expectation for HEAD requests. For more info see `expect()`.
1352
1419
  *
1353
- * @param {string|RegExp} url HTTP url.
1420
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1421
+ * and returns true if the url match the current definition.
1354
1422
  * @param {Object=} headers HTTP headers.
1355
1423
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1356
- * request is handled.
1424
+ * request is handled. You can save this object for later use and invoke `respond` again in
1425
+ * order to change how a matched request is handled.
1357
1426
  */
1358
1427
 
1359
1428
  /**
@@ -1362,10 +1431,12 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1362
1431
  * @description
1363
1432
  * Creates a new request expectation for DELETE requests. For more info see `expect()`.
1364
1433
  *
1365
- * @param {string|RegExp} url HTTP url.
1434
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1435
+ * and returns true if the url match the current definition.
1366
1436
  * @param {Object=} headers HTTP headers.
1367
1437
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1368
- * request is handled.
1438
+ * request is handled. You can save this object for later use and invoke `respond` again in
1439
+ * order to change how a matched request is handled.
1369
1440
  */
1370
1441
 
1371
1442
  /**
@@ -1374,13 +1445,15 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1374
1445
  * @description
1375
1446
  * Creates a new request expectation for POST requests. For more info see `expect()`.
1376
1447
  *
1377
- * @param {string|RegExp} url HTTP url.
1448
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1449
+ * and returns true if the url match the current definition.
1378
1450
  * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1379
1451
  * receives data string and returns true if the data is as expected, or Object if request body
1380
1452
  * is in JSON format.
1381
1453
  * @param {Object=} headers HTTP headers.
1382
1454
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1383
- * request is handled.
1455
+ * request is handled. You can save this object for later use and invoke `respond` again in
1456
+ * order to change how a matched request is handled.
1384
1457
  */
1385
1458
 
1386
1459
  /**
@@ -1389,13 +1462,15 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1389
1462
  * @description
1390
1463
  * Creates a new request expectation for PUT requests. For more info see `expect()`.
1391
1464
  *
1392
- * @param {string|RegExp} url HTTP url.
1465
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1466
+ * and returns true if the url match the current definition.
1393
1467
  * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1394
1468
  * receives data string and returns true if the data is as expected, or Object if request body
1395
1469
  * is in JSON format.
1396
1470
  * @param {Object=} headers HTTP headers.
1397
1471
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1398
- * request is handled.
1472
+ * request is handled. You can save this object for later use and invoke `respond` again in
1473
+ * order to change how a matched request is handled.
1399
1474
  */
1400
1475
 
1401
1476
  /**
@@ -1404,13 +1479,15 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1404
1479
  * @description
1405
1480
  * Creates a new request expectation for PATCH requests. For more info see `expect()`.
1406
1481
  *
1407
- * @param {string|RegExp} url HTTP url.
1482
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1483
+ * and returns true if the url match the current definition.
1408
1484
  * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1409
1485
  * receives data string and returns true if the data is as expected, or Object if request body
1410
1486
  * is in JSON format.
1411
1487
  * @param {Object=} headers HTTP headers.
1412
1488
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1413
- * request is handled.
1489
+ * request is handled. You can save this object for later use and invoke `respond` again in
1490
+ * order to change how a matched request is handled.
1414
1491
  */
1415
1492
 
1416
1493
  /**
@@ -1419,9 +1496,11 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1419
1496
  * @description
1420
1497
  * Creates a new request expectation for JSONP requests. For more info see `expect()`.
1421
1498
  *
1422
- * @param {string|RegExp} url HTTP url.
1499
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1500
+ * and returns true if the url match the current definition.
1423
1501
  * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1424
- * request is handled.
1502
+ * request is handled. You can save this object for later use and invoke `respond` again in
1503
+ * order to change how a matched request is handled.
1425
1504
  */
1426
1505
  createShortMethods('expect');
1427
1506
 
@@ -1436,11 +1515,11 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1436
1515
  * all pending requests will be flushed. If there are no pending requests when the flush method
1437
1516
  * is called an exception is thrown (as this typically a sign of programming error).
1438
1517
  */
1439
- $httpBackend.flush = function(count) {
1440
- $rootScope.$digest();
1518
+ $httpBackend.flush = function(count, digest) {
1519
+ if (digest !== false) $rootScope.$digest();
1441
1520
  if (!responses.length) throw new Error('No pending request to flush !');
1442
1521
 
1443
- if (angular.isDefined(count)) {
1522
+ if (angular.isDefined(count) && count !== null) {
1444
1523
  while (count--) {
1445
1524
  if (!responses.length) throw new Error('No more pending request to flush !');
1446
1525
  responses.shift()();
@@ -1450,7 +1529,7 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1450
1529
  responses.shift()();
1451
1530
  }
1452
1531
  }
1453
- $httpBackend.verifyNoOutstandingExpectation();
1532
+ $httpBackend.verifyNoOutstandingExpectation(digest);
1454
1533
  };
1455
1534
 
1456
1535
 
@@ -1468,8 +1547,8 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1468
1547
  * afterEach($httpBackend.verifyNoOutstandingExpectation);
1469
1548
  * ```
1470
1549
  */
1471
- $httpBackend.verifyNoOutstandingExpectation = function() {
1472
- $rootScope.$digest();
1550
+ $httpBackend.verifyNoOutstandingExpectation = function(digest) {
1551
+ if (digest !== false) $rootScope.$digest();
1473
1552
  if (expectations.length) {
1474
1553
  throw new Error('Unsatisfied requests: ' + expectations.join(', '));
1475
1554
  }
@@ -1513,7 +1592,7 @@ function createHttpBackendMock($rootScope, $delegate, $browser) {
1513
1592
 
1514
1593
 
1515
1594
  function createShortMethods(prefix) {
1516
- angular.forEach(['GET', 'DELETE', 'JSONP'], function(method) {
1595
+ angular.forEach(['GET', 'DELETE', 'JSONP', 'HEAD'], function(method) {
1517
1596
  $httpBackend[prefix + method] = function(url, headers) {
1518
1597
  return $httpBackend[prefix](method, url, undefined, headers);
1519
1598
  };
@@ -1543,6 +1622,7 @@ function MockHttpExpectation(method, url, data, headers) {
1543
1622
  this.matchUrl = function(u) {
1544
1623
  if (!url) return true;
1545
1624
  if (angular.isFunction(url.test)) return url.test(u);
1625
+ if (angular.isFunction(url)) return url(u);
1546
1626
  return url == u;
1547
1627
  };
1548
1628
 
@@ -1629,7 +1709,7 @@ function MockXhr() {
1629
1709
  * that adds a "flush" and "verifyNoPendingTasks" methods.
1630
1710
  */
1631
1711
 
1632
- angular.mock.$TimeoutDecorator = function($delegate, $browser) {
1712
+ angular.mock.$TimeoutDecorator = ['$delegate', '$browser', function ($delegate, $browser) {
1633
1713
 
1634
1714
  /**
1635
1715
  * @ngdoc method
@@ -1668,9 +1748,9 @@ angular.mock.$TimeoutDecorator = function($delegate, $browser) {
1668
1748
  }
1669
1749
 
1670
1750
  return $delegate;
1671
- };
1751
+ }];
1672
1752
 
1673
- angular.mock.$RAFDecorator = function($delegate) {
1753
+ angular.mock.$RAFDecorator = ['$delegate', function($delegate) {
1674
1754
  var queue = [];
1675
1755
  var rafFn = function(fn) {
1676
1756
  var index = queue.length;
@@ -1696,9 +1776,9 @@ angular.mock.$RAFDecorator = function($delegate) {
1696
1776
  };
1697
1777
 
1698
1778
  return rafFn;
1699
- };
1779
+ }];
1700
1780
 
1701
- angular.mock.$AsyncCallbackDecorator = function($delegate) {
1781
+ angular.mock.$AsyncCallbackDecorator = ['$delegate', function($delegate) {
1702
1782
  var callbacks = [];
1703
1783
  var addFn = function(fn) {
1704
1784
  callbacks.push(fn);
@@ -1710,7 +1790,7 @@ angular.mock.$AsyncCallbackDecorator = function($delegate) {
1710
1790
  callbacks = [];
1711
1791
  };
1712
1792
  return addFn;
1713
- };
1793
+ }];
1714
1794
 
1715
1795
  /**
1716
1796
  *
@@ -1824,12 +1904,14 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1824
1904
  * Creates a new backend definition.
1825
1905
  *
1826
1906
  * @param {string} method HTTP method.
1827
- * @param {string|RegExp} url HTTP url.
1907
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1908
+ * and returns true if the url match the current definition.
1828
1909
  * @param {(string|RegExp)=} data HTTP request body.
1829
1910
  * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
1830
1911
  * object and returns true if the headers match the current definition.
1831
1912
  * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1832
- * control how a matched request is handled.
1913
+ * control how a matched request is handled. You can save this object for later use and invoke
1914
+ * `respond` or `passThrough` again in order to change how a matched request is handled.
1833
1915
  *
1834
1916
  * - respond –
1835
1917
  * `{function([status,] data[, headers, statusText])
@@ -1840,6 +1922,7 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1840
1922
  * - passThrough – `{function()}` – Any request matching a backend definition with
1841
1923
  * `passThrough` handler will be passed through to the real backend (an XHR request will be made
1842
1924
  * to the server.)
1925
+ * - Both methods return the `requestHandler` object for possible overrides.
1843
1926
  */
1844
1927
 
1845
1928
  /**
@@ -1849,10 +1932,12 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1849
1932
  * @description
1850
1933
  * Creates a new backend definition for GET requests. For more info see `when()`.
1851
1934
  *
1852
- * @param {string|RegExp} url HTTP url.
1935
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1936
+ * and returns true if the url match the current definition.
1853
1937
  * @param {(Object|function(Object))=} headers HTTP headers.
1854
1938
  * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1855
- * control how a matched request is handled.
1939
+ * control how a matched request is handled. You can save this object for later use and invoke
1940
+ * `respond` or `passThrough` again in order to change how a matched request is handled.
1856
1941
  */
1857
1942
 
1858
1943
  /**
@@ -1862,10 +1947,12 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1862
1947
  * @description
1863
1948
  * Creates a new backend definition for HEAD requests. For more info see `when()`.
1864
1949
  *
1865
- * @param {string|RegExp} url HTTP url.
1950
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1951
+ * and returns true if the url match the current definition.
1866
1952
  * @param {(Object|function(Object))=} headers HTTP headers.
1867
1953
  * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1868
- * control how a matched request is handled.
1954
+ * control how a matched request is handled. You can save this object for later use and invoke
1955
+ * `respond` or `passThrough` again in order to change how a matched request is handled.
1869
1956
  */
1870
1957
 
1871
1958
  /**
@@ -1875,10 +1962,12 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1875
1962
  * @description
1876
1963
  * Creates a new backend definition for DELETE requests. For more info see `when()`.
1877
1964
  *
1878
- * @param {string|RegExp} url HTTP url.
1965
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1966
+ * and returns true if the url match the current definition.
1879
1967
  * @param {(Object|function(Object))=} headers HTTP headers.
1880
1968
  * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1881
- * control how a matched request is handled.
1969
+ * control how a matched request is handled. You can save this object for later use and invoke
1970
+ * `respond` or `passThrough` again in order to change how a matched request is handled.
1882
1971
  */
1883
1972
 
1884
1973
  /**
@@ -1888,11 +1977,13 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1888
1977
  * @description
1889
1978
  * Creates a new backend definition for POST requests. For more info see `when()`.
1890
1979
  *
1891
- * @param {string|RegExp} url HTTP url.
1980
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1981
+ * and returns true if the url match the current definition.
1892
1982
  * @param {(string|RegExp)=} data HTTP request body.
1893
1983
  * @param {(Object|function(Object))=} headers HTTP headers.
1894
1984
  * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1895
- * control how a matched request is handled.
1985
+ * control how a matched request is handled. You can save this object for later use and invoke
1986
+ * `respond` or `passThrough` again in order to change how a matched request is handled.
1896
1987
  */
1897
1988
 
1898
1989
  /**
@@ -1902,11 +1993,13 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1902
1993
  * @description
1903
1994
  * Creates a new backend definition for PUT requests. For more info see `when()`.
1904
1995
  *
1905
- * @param {string|RegExp} url HTTP url.
1996
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1997
+ * and returns true if the url match the current definition.
1906
1998
  * @param {(string|RegExp)=} data HTTP request body.
1907
1999
  * @param {(Object|function(Object))=} headers HTTP headers.
1908
2000
  * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1909
- * control how a matched request is handled.
2001
+ * control how a matched request is handled. You can save this object for later use and invoke
2002
+ * `respond` or `passThrough` again in order to change how a matched request is handled.
1910
2003
  */
1911
2004
 
1912
2005
  /**
@@ -1916,11 +2009,13 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1916
2009
  * @description
1917
2010
  * Creates a new backend definition for PATCH requests. For more info see `when()`.
1918
2011
  *
1919
- * @param {string|RegExp} url HTTP url.
2012
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
2013
+ * and returns true if the url match the current definition.
1920
2014
  * @param {(string|RegExp)=} data HTTP request body.
1921
2015
  * @param {(Object|function(Object))=} headers HTTP headers.
1922
2016
  * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1923
- * control how a matched request is handled.
2017
+ * control how a matched request is handled. You can save this object for later use and invoke
2018
+ * `respond` or `passThrough` again in order to change how a matched request is handled.
1924
2019
  */
1925
2020
 
1926
2021
  /**
@@ -1930,30 +2025,17 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1930
2025
  * @description
1931
2026
  * Creates a new backend definition for JSONP requests. For more info see `when()`.
1932
2027
  *
1933
- * @param {string|RegExp} url HTTP url.
2028
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
2029
+ * and returns true if the url match the current definition.
1934
2030
  * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1935
- * control how a matched request is handled.
2031
+ * control how a matched request is handled. You can save this object for later use and invoke
2032
+ * `respond` or `passThrough` again in order to change how a matched request is handled.
1936
2033
  */
1937
2034
  angular.mock.e2e = {};
1938
2035
  angular.mock.e2e.$httpBackendDecorator =
1939
2036
  ['$rootScope', '$delegate', '$browser', createHttpBackendMock];
1940
2037
 
1941
2038
 
1942
- angular.mock.clearDataCache = function() {
1943
- var key,
1944
- cache = angular.element.cache;
1945
-
1946
- for(key in cache) {
1947
- if (Object.prototype.hasOwnProperty.call(cache,key)) {
1948
- var handle = cache[key].handle;
1949
-
1950
- handle && angular.element(handle.elem).off();
1951
- delete cache[key];
1952
- }
1953
- }
1954
- };
1955
-
1956
-
1957
2039
  if(window.jasmine || window.mocha) {
1958
2040
 
1959
2041
  var currentSpec = null,
@@ -1984,8 +2066,6 @@ if(window.jasmine || window.mocha) {
1984
2066
  injector.get('$browser').pollFns.length = 0;
1985
2067
  }
1986
2068
 
1987
- angular.mock.clearDataCache();
1988
-
1989
2069
  // clean up jquery's fragment cache
1990
2070
  angular.forEach(angular.element.fragments, function(val, key) {
1991
2071
  delete angular.element.fragments[key];
@@ -2148,14 +2228,28 @@ if(window.jasmine || window.mocha) {
2148
2228
  /////////////////////
2149
2229
  function workFn() {
2150
2230
  var modules = currentSpec.$modules || [];
2151
-
2231
+ var strictDi = !!currentSpec.$injectorStrict;
2152
2232
  modules.unshift('ngMock');
2153
2233
  modules.unshift('ng');
2154
2234
  var injector = currentSpec.$injector;
2155
2235
  if (!injector) {
2156
- injector = currentSpec.$injector = angular.injector(modules);
2236
+ if (strictDi) {
2237
+ // If strictDi is enabled, annotate the providerInjector blocks
2238
+ angular.forEach(modules, function(moduleFn) {
2239
+ if (typeof moduleFn === "function") {
2240
+ angular.injector.$$annotate(moduleFn);
2241
+ }
2242
+ });
2243
+ }
2244
+ injector = currentSpec.$injector = angular.injector(modules, strictDi);
2245
+ currentSpec.$injectorStrict = strictDi;
2157
2246
  }
2158
2247
  for(var i = 0, ii = blockFns.length; i < ii; i++) {
2248
+ if (currentSpec.$injectorStrict) {
2249
+ // If the injector is strict / strictDi, and the spec wants to inject using automatic
2250
+ // annotation, then annotate the function here.
2251
+ injector.annotate(blockFns[i]);
2252
+ }
2159
2253
  try {
2160
2254
  /* jshint -W040 *//* Jasmine explicitly provides a `this` object when calling functions */
2161
2255
  injector.invoke(blockFns[i] || angular.noop, this);
@@ -2171,6 +2265,22 @@ if(window.jasmine || window.mocha) {
2171
2265
  }
2172
2266
  }
2173
2267
  };
2268
+
2269
+
2270
+ angular.mock.inject.strictDi = function(value) {
2271
+ value = arguments.length ? !!value : true;
2272
+ return isSpecRunning() ? workFn() : workFn;
2273
+
2274
+ function workFn() {
2275
+ if (value !== currentSpec.$injectorStrict) {
2276
+ if (currentSpec.$injector) {
2277
+ throw new Error('Injector already created, can not modify strict annotations');
2278
+ } else {
2279
+ currentSpec.$injectorStrict = value;
2280
+ }
2281
+ }
2282
+ }
2283
+ };
2174
2284
  }
2175
2285
 
2176
2286