aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scenario/application-account.html4
-rw-r--r--scenario/application.html17
-rw-r--r--scenario/widgets.html2
-rw-r--r--src/Resource.js2
-rw-r--r--test/ResourceSpec.js13
-rw-r--r--test/angular-mocks.js20
-rw-r--r--test/testabilityPatch.js9
7 files changed, 50 insertions, 17 deletions
diff --git a/scenario/application-account.html b/scenario/application-account.html
index 8520d07c..a43deffc 100644
--- a/scenario/application-account.html
+++ b/scenario/application-account.html
@@ -1,4 +1,6 @@
-<div>
+<div ng-controller="AccountController">
account page goes here!
+ <input type="text" name="name" value="misko"/>
+ <button ng-click="hello()">hello</button>
</div>
diff --git a/scenario/application.html b/scenario/application.html
index be6390f6..6b6ced69 100644
--- a/scenario/application.html
+++ b/scenario/application.html
@@ -3,6 +3,18 @@
<head>
<link rel="stylesheet" type="text/css" href="style.css"></link>
<script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
+ <script>
+ function AccountController(){
+ }
+
+ AccountController.prototype = {
+ hello: function(){
+ alert(this.name);
+ }
+
+ };
+
+ </script>
</head>
<body ng-init="$window.$scope = this">
[ <a href="#login">login</a>
@@ -11,9 +23,12 @@
<ng:switch on="$location.hashPath">
<div ng-switch-when="login">login screen</div>
- <ng:include ng-switch-when="account" src="application-account.html"></ng:include>
+ <ng:include ng-switch-when="account" src="'application-account.html'"></ng:include>
</ng:switch>
+
+ (( input name ))
+
<pre>$location={{$location}}</pre>
</body>
</html>
diff --git a/scenario/widgets.html b/scenario/widgets.html
index 1341f7cb..61badf1c 100644
--- a/scenario/widgets.html
+++ b/scenario/widgets.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
diff --git a/src/Resource.js b/src/Resource.js
index 9fe60788..34ad1c5d 100644
--- a/src/Resource.js
+++ b/src/Resource.js
@@ -83,7 +83,7 @@ ResourceFactory.prototype = {
}
var value = action.isArray ? [] : new Resource(data);
- self.xhr(action.method, route.url(extend({}, action.params || {}, extractParams(data), params)), data, function(response) {
+ self.xhr(action.method, route.url(extend({}, action.params || {}, extractParams(data), params)), data, function(status, response) {
if (action.isArray) {
foreach(response, function(item){
value.push(new Resource(item));
diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js
index 91900a91..08ca86b3 100644
--- a/test/ResourceSpec.js
+++ b/test/ResourceSpec.js
@@ -60,8 +60,9 @@ describe("resource", function() {
var xhr, resource, CreditCard, callback;
beforeEach(function(){
- xhr = new MockXHR();
- resource = new ResourceFactory(bind(xhr, xhr.method));
+ var browser = new MockBrowser();
+ xhr = browser.xhr;
+ resource = new ResourceFactory(xhr);
CreditCard = resource.route('/CreditCard/:id:verb', {id:'@id.key'}, {
charge:{
method:'POST',
@@ -95,7 +96,7 @@ describe("resource", function() {
});
it("should create resource", function(){
- xhr.expectPOST('/CreditCard').data({name:'misko'}).respond({id:123, name:'misko'});
+ xhr.expectPOST('/CreditCard', {name:'misko'}).respond({id:123, name:'misko'});
var cc = CreditCard.save({name:'misko'}, callback);
nakedExpect(cc).toEqual({name:'misko'});
@@ -117,7 +118,7 @@ describe("resource", function() {
});
it("should update resource", function(){
- xhr.expectPOST('/CreditCard/123').data({id:{key:123}, name:'misko'}).respond({id:{key:123}, name:'rama'});
+ xhr.expectPOST('/CreditCard/123', {id:{key:123}, name:'misko'}).respond({id:{key:123}, name:'rama'});
var cc = CreditCard.save({id:{key:123}, name:'misko'}, callback);
nakedExpect(cc).toEqual({id:{key:123}, name:'misko'});
@@ -148,13 +149,13 @@ describe("resource", function() {
});
it('should post charge verb', function(){
- xhr.expectPOST('/CreditCard/123!charge?amount=10').data({auth:'abc'}).respond({success:'ok'});
+ xhr.expectPOST('/CreditCard/123!charge?amount=10', {auth:'abc'}).respond({success:'ok'});
CreditCard.charge({id:123, amount:10},{auth:'abc'}, callback);
});
it('should create on save', function(){
- xhr.expectPOST('/CreditCard').data({name:'misko'}).respond({id:123});
+ xhr.expectPOST('/CreditCard', {name:'misko'}).respond({id:123});
var cc = new CreditCard();
expect(cc.$get).not.toBeDefined();
expect(cc.$query).not.toBeDefined();
diff --git a/test/angular-mocks.js b/test/angular-mocks.js
index 3e272313..715b4d75 100644
--- a/test/angular-mocks.js
+++ b/test/angular-mocks.js
@@ -23,11 +23,19 @@
*/
function MockBrowser() {
- var self = this, expectations = {}, requests = [];
+ var self = this,
+ expectations = {},
+ requests = [];
self.url = "http://server";
self.watches = [];
- self.xhr = function(method, url, callback) {
+ self.xhr = function(method, url, data, callback) {
+ if (isFunction(data)) {
+ callback = data;
+ data = null;
+ }
+ if (data && isObject(data)) data = angular.toJson(data);
+ if (data && isString(data)) url += "|" + data;
var expect = expectations[method] || {};
var response = expect[url];
if (!response) {
@@ -39,7 +47,9 @@ function MockBrowser() {
};
self.xhr.expectations = expectations;
self.xhr.requests = requests;
- self.xhr.expect = function(method, url) {
+ self.xhr.expect = function(method, url, data) {
+ if (data && isObject(data)) data = angular.toJson(data);
+ if (data && isString(data)) url += "|" + data;
var expect = expectations[method] || (expectations[method] = {});
return {
respond: function(response) {
@@ -47,6 +57,10 @@ function MockBrowser() {
}
};
};
+ self.xhr.expectGET = angular.bind(self, self.xhr.expect, 'GET');
+ self.xhr.expectPOST = angular.bind(self, self.xhr.expect, 'POST');
+ self.xhr.expectDELETE = angular.bind(self, self.xhr.expect, 'DELETE');
+ self.xhr.expectPUT = angular.bind(self, self.xhr.expect, 'PUT');
self.xhr.flush = function() {
while(requests.length) {
requests.pop()();
diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js
index ff537a09..572e6a36 100644
--- a/test/testabilityPatch.js
+++ b/test/testabilityPatch.js
@@ -10,20 +10,21 @@ function childNode(element, index) {
}
extend(angular, {
- 'element': jqLite,
+ 'bind': bind,
'compile': compile,
- 'scope': createScope,
'copy': copy,
+ 'element': jqLite,
'extend': extend,
'foreach': foreach,
- 'noop':noop,
'identity':identity,
'isUndefined': isUndefined,
'isDefined': isDefined,
'isString': isString,
'isFunction': isFunction,
'isNumber': isNumber,
- 'isArray': isArray
+ 'isArray': isArray,
+ 'noop':noop,
+ 'scope': createScope
});