Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Added PATCH support to resource.js and angular-mock.js #891

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2010 Adam Abrons and Misko Hevery http://getangular.com
Copyright (c) 2010-2012 Google, Inc. http://angularjs.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added images/logo/AngularShieldLogo.graffle/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

////////////////////////////////////

if (typeof document.getAttribute == 'undefined')
document.getAttribute = function() {};

/**
* @ngdoc function
* @name angular.lowercase
Expand Down
2 changes: 1 addition & 1 deletion src/angular-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @license AngularJS
* (c) 2010-2011 AngularJS http://angularjs.org
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
*/
(function(window, document) {
Expand Down
2 changes: 1 addition & 1 deletion src/angular.prefix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license AngularJS v"NG_VERSION_FULL"
* (c) 2010-2012 AngularJS http://angularjs.org
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
*/
(function(window, document, undefined) {
2 changes: 1 addition & 1 deletion src/loader.prefix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license AngularJS v"NG_VERSION_FULL"
* (c) 2010-2012 AngularJS http://angularjs.org
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
*/
'use strict';
Expand Down
2 changes: 1 addition & 1 deletion src/module.prefix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license AngularJS v"NG_VERSION_FULL"
* (c) 2010-2012 AngularJS http://angularjs.org
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
*/
(function(angular) {
15 changes: 10 additions & 5 deletions src/ng/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,17 @@ function $CompileProvider($provide) {
addTextInterpolateDirective(directives, node.nodeValue);
break;
case 8: /* Comment */
match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
if (match) {
nName = directiveNormalize(match[1]);
if (addDirective(directives, nName, 'M', maxPriority)) {
attrs[nName] = trim(match[2]);
try {
match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
if (match) {
nName = directiveNormalize(match[1]);
if (addDirective(directives, nName, 'M', maxPriority)) {
attrs[nName] = trim(match[2]);
}
}
} catch (e) {
// turns out that under some circumstances IE9 throws errors when one attempts to read comment's node value.
// Just ignore it and continue. (Can't seem to reproduce in test case.)
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ng/directive/ngBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* Once scenario in which the use of `ngBind` is prefered over `{{ expression }}` binding is when
* it's desirable to put bindings into template that is momentarily displayed by the browser in its
* raw state before Angular compiles it. Since `ngBind` is an element attribute, it makes make the
* raw state before Angular compiles it. Since `ngBind` is an element attribute, it makes the
* bindings invisible to the user while the page is loading.
*
* An alternative solution to this problem would be using the
Expand Down
7 changes: 5 additions & 2 deletions src/ng/directive/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ var scriptDirective = ['$templateCache', function($templateCache) {
terminal: true,
compile: function(element, attr) {
if (attr.type == 'text/ng-template') {
var templateUrl = attr.id;
$templateCache.put(templateUrl, element.text());
var templateUrl = attr.id,
// IE is not consistent, in scripts we have to read .text but in other nodes we have to read .textContent
text = element[0].text;

$templateCache.put(templateUrl, text);
}
}
};
Expand Down
30 changes: 29 additions & 1 deletion src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,20 @@ function createHttpBackendMock($delegate, $browser) {
* request is handled.
*/

/**
* @ngdoc method
* @name angular.module.ngMock.$httpBackend#expectPATCH
* @methodOf angular.module.ngMock.$httpBackend
* @description
* Creates a new request expectation for PATCH requests. For more info see `expect()`.
*
* @param {string|RegExp} url HTTP url.
* @param {(string|RegExp)=} data HTTP request body.
* @param {Object=} headers HTTP headers.
* @returns {requestHandler} Returns an object with `respond` method that control how a matched
* request is handled.
*/

/**
* @ngdoc method
* @name angular.module.ngMock.$httpBackend#expectJSONP
Expand Down Expand Up @@ -1220,7 +1234,7 @@ function createHttpBackendMock($delegate, $browser) {
}
});

angular.forEach(['PUT', 'POST'], function(method) {
angular.forEach(['PUT', 'POST', 'PATCH'], function(method) {
$httpBackend[prefix + method] = function(url, data, headers) {
return $httpBackend[prefix](method, url, data, headers)
}
Expand Down Expand Up @@ -1483,6 +1497,20 @@ angular.module('ngMockE2E', ['ng']).config(function($provide) {
* control how a matched request is handled.
*/

/**
* @ngdoc method
* @name angular.module.ngMockE2E.$httpBackend#whenPATCH
* @methodOf angular.module.ngMockE2E.$httpBackend
* @description
* Creates a new backend definition for PATCH requests. For more info see `when()`.
*
* @param {string|RegExp} url HTTP url.
* @param {(string|RegExp)=} data HTTP request body.
* @param {(Object|function(Object))=} headers HTTP headers.
* @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
* control how a matched request is handled.
*/

/**
* @ngdoc method
* @name angular.module.ngMockE2E.$httpBackend#whenJSONP
Expand Down
6 changes: 3 additions & 3 deletions src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ angular.module('ngResource', ['ng']).
}

forEach(actions, function(action, name) {
var isPostOrPut = action.method == 'POST' || action.method == 'PUT';
var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH';
Resource[name] = function(a1, a2, a3, a4) {
var params = {};
var data;
Expand Down Expand Up @@ -349,7 +349,7 @@ angular.module('ngResource', ['ng']).
}
case 1:
if (isFunction(a1)) success = a1;
else if (isPostOrPut) data = a1;
else if (hasBody) data = a1;
else params = a1;
break;
case 0: break;
Expand Down Expand Up @@ -409,7 +409,7 @@ angular.module('ngResource', ['ng']).
throw "Expected between 1-3 arguments [params, success, error], got " +
arguments.length + " arguments.";
}
var data = isPostOrPut ? this : undefined;
var data = hasBody ? this : undefined;
Resource[name].call(this, params, data, success, error);
};
});
Expand Down
2 changes: 1 addition & 1 deletion src/ngScenario/angular.prefix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license AngularJS v"NG_VERSION_FULL"
* (c) 2010-2011 AngularJS http://angularjs.org
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
*/
(function(window, document){
Expand Down
2 changes: 1 addition & 1 deletion src/ngScenario/jstd-scenario-adapter/angular.prefix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @license AngularJS v"NG_VERSION_FULL"
* (c) 2010-2011 AngularJS http://angularjs.org
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
*/
(function(window) {
17 changes: 6 additions & 11 deletions test/ng/directive/scriptSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ describe('scriptDirective', function() {

it('should populate $templateCache with contents of a ng-template script element', inject(
function($compile, $templateCache) {
if (msie <=8) return;
// in ie8 it is not possible to create a script tag with the right content.
// it always comes up as empty. I was trying to set the text of the
// script tag, but that did not work either, so I gave up.
$compile('<div>foo' +
'<script id="/ignore">ignore me</script>' +
'<script type="text/ng-template" id="/myTemplate.html"><x>{{y}}</x></script>' +
Expand All @@ -26,19 +22,18 @@ describe('scriptDirective', function() {


it('should not compile scripts', inject(function($compile, $templateCache, $rootScope) {
if (msie <=8) return; // see above

var doc = jqLite('<div></div>');
// jQuery is too smart and removes
doc[0].innerHTML = '<script type="text/javascript">some {{binding}}</script>' +
'<script type="text/ng-template" id="/some">other {{binding}}</script>';
// jQuery is too smart and removes script tags
doc[0].innerHTML = 'foo' +
'<script type="text/javascript">some {{binding}}</script>' +
'<script type="text/ng-template" id="/some">other {{binding}}</script>';

$compile(doc)($rootScope);
$rootScope.$digest();

var scripts = doc.find('script');
expect(scripts.eq(0).text()).toBe('some {{binding}}');
expect(scripts.eq(1).text()).toBe('other {{binding}}');
expect(scripts.eq(0)[0].text).toBe('some {{binding}}');
expect(scripts.eq(1)[0].text).toBe('other {{binding}}');
dealoc(doc);
}));
});
2 changes: 1 addition & 1 deletion test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ describe('ngMock', function() {

describe('expect/when shortcuts', function() {
angular.forEach(['expect', 'when'], function(prefix) {
angular.forEach(['GET', 'POST', 'PUT', 'DELETE', 'JSONP'], function(method) {
angular.forEach(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'JSONP'], function(method) {
var shortcut = prefix + method;
it('should provide ' + shortcut + ' shortcut method', function() {
hb[shortcut]('/foo').respond('bar');
Expand Down