aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.idea/.gitignore1
-rw-r--r--Rakefile1
-rw-r--r--example/tweeter/tweeter_addressbook.html2
-rw-r--r--example/tweeter/tweeterclient.js34
-rw-r--r--jsTestDriver.conf6
-rw-r--r--src/Resource.js4
-rw-r--r--src/angular-bootstrap.js1
-rw-r--r--test/ResourceSpec.js7
-rw-r--r--test/scenario/StepsTest.js2
9 files changed, 32 insertions, 26 deletions
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..a7c382ed
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1 @@
+workspace.xml
diff --git a/Rakefile b/Rakefile
index 883198dc..5e0bf008 100644
--- a/Rakefile
+++ b/Rakefile
@@ -46,6 +46,7 @@ task :compile do
src/JSON.js \
src/Model.js \
src/Parser.js \
+ src/Resource.js \
src/Scope.js \
src/Server.js \
src/Users.js \
diff --git a/example/tweeter/tweeter_addressbook.html b/example/tweeter/tweeter_addressbook.html
index 64a3f95e..92121d5f 100644
--- a/example/tweeter/tweeter_addressbook.html
+++ b/example/tweeter/tweeter_addressbook.html
@@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="../../css/angular.css">
<script type="text/javascript" src="../../lib/underscore/underscore.js"></script>
<script type="text/javascript" src="../../lib/jquery/jquery-1.4.js"></script>
- <script type="text/javascript" src="../../angular.js"></script>
+ <script type="text/javascript" src="../../src/angular-bootstrap.js"></script>
<script type="text/javascript" src="tweeterclient.js"></script>
</head>
<body ng-class="status" ng-init="mute={}" ng-watch="$anchor.user: tweets = fetchTweets($anchor.user)">
diff --git a/example/tweeter/tweeterclient.js b/example/tweeter/tweeterclient.js
index 8c68fac0..d6fdd084 100644
--- a/example/tweeter/tweeterclient.js
+++ b/example/tweeter/tweeterclient.js
@@ -1,28 +1,26 @@
function noop(){}
$(document).ready(function(){
+ function xhr(method, url, data, callback){
+ jQuery.getJSON(url, function(){
+ callback.apply(this, arguments);
+ scope.updateView();
+ })
+ }
+
+ var resourceFactory = new ResourceFactory(xhr);
+
+ var Tweeter = resourceFactory.route("http://twitter.com/statuses/:service:username.json", {}, {
+ home: {method:'GET', params: {service:'home_timeline'}, isArray:true },
+ user: {method:'GET', params: {service:'user_timeline/'}, isArray:true }
+ });
+
+
var scope = window.scope = angular.compile(document, {
location:angular.startUrlWatcher()
});
- scope.getJSON = function(url, callback) {
- var list = [];
- var self = this;
- self.set('status', 'fetching');
- $.getJSON(url, function(response, code){
- _(response).forEach(function(v,k){
- list[k] = v;
- });
- (callback||noop)(response);
- self.set('status', '');
- self.updateView();
- });
- return list;
- };
function fetchTweets(username){
- return scope.getJSON(
- username ?
- "http://twitter.com/statuses/user_timeline/"+username+".json" :
- "http://twitter.com/statuses/home_timeline.json");
+ return username ? Tweeter.user({username: username}) : Tweeter.home();
}
scope.set('fetchTweets', fetchTweets);
diff --git a/jsTestDriver.conf b/jsTestDriver.conf
index c048a294..da821ad1 100644
--- a/jsTestDriver.conf
+++ b/jsTestDriver.conf
@@ -9,10 +9,10 @@ load:
- lib/underscore/underscore.js
- src/Angular.js
- src/*.js
- - src/test/_namespace.js
- - src/test/*.js
+ - src/scenario/_namespace.js
+ - src/scenario/*.js
- test/testabilityPatch.js
- - test/test/*.js
+ - test/scenario/*.js
- test/*.js
exclude:
diff --git a/src/Resource.js b/src/Resource.js
index c0c7934c..587c331e 100644
--- a/src/Resource.js
+++ b/src/Resource.js
@@ -49,7 +49,7 @@ ResourceFactory.prototype = {
actions = $.extend({}, ResourceFactory.DEFAULT_ACTIONS, actions);
function extractParams(data){
var ids = {};
- foreach(paramDefaults, function(value, key){
+ foreach(paramDefaults || {}, function(value, key){
ids[key] = value.charAt && value.charAt(0) == '@' ? Scope.getter(data, value.substr(1)) : value;
});
return ids;
@@ -83,7 +83,7 @@ ResourceFactory.prototype = {
}
var value = action.isArray ? [] : new Resource(data);
- self.xhr.method(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(response) {
if (action.isArray) {
foreach(response, function(item){
value.push(new Resource(item));
diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js
index 0f7cd2ea..d2b2ff9c 100644
--- a/src/angular-bootstrap.js
+++ b/src/angular-bootstrap.js
@@ -46,6 +46,7 @@
addScript("/JSON.js");
addScript("/Model.js");
addScript("/Parser.js");
+ addScript("/Resource.js");
addScript("/Scope.js");
addScript("/Server.js");
addScript("/Users.js");
diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js
index 799c7378..0c7af00a 100644
--- a/test/ResourceSpec.js
+++ b/test/ResourceSpec.js
@@ -61,7 +61,7 @@ describe("resource", function() {
beforeEach(function(){
xhr = new MockXHR();
- resource = new ResourceFactory(xhr);
+ resource = new ResourceFactory(_(xhr.method).bind(xhr));
CreditCard = resource.route('/CreditCard/:id:verb', {id:'@id.key'}, {
charge:{
method:'POST',
@@ -80,6 +80,11 @@ describe("resource", function() {
expect(typeof CreditCard.query).toBe('function');
});
+ it('should default to empty parameters', function(){
+ xhr.expectGET('URL').respond({});
+ resource.route('URL').query();
+ });
+
it("should build resource with default param", function(){
xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'});
var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05});
diff --git a/test/scenario/StepsTest.js b/test/scenario/StepsTest.js
index 9d64d0a9..32ef637d 100644
--- a/test/scenario/StepsTest.js
+++ b/test/scenario/StepsTest.js
@@ -2,6 +2,6 @@ StepsTest = TestCase("StepsTest");
StepsTest.prototype.testGivenDataset=function(){
var self = {frame:{}, dataset:[]};
- angular.test.GIVEN.dataset.call(self);
+ angular.scenario.GIVEN.dataset.call(self);
assertEquals('$DATASET:{"dataset":[]}', self.frame.name);
};