From 293f34cd64886a1dddae9c295fafde5c47029a3b Mon Sep 17 00:00:00 2001 From: Alkis Evlogimenos Date: Wed, 15 Sep 2010 19:27:58 +0200 Subject: Expose GET operations on resources as well. This allows us to read "partials". The pattern is demostrated in the unittest: Resource.query returns a list of "keys" to resources, which are partially defined. They have enough data to allow $get to fetch the whole gamout. Then $get fetches all the details of the resource. --- test/ResourceSpec.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 1ac43d74..435176b0 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -70,6 +70,21 @@ describe("resource", function() { expect(callback).wasCalledWith(cc); }); + it("should read partial resource", function(){ + xhr.expectGET("/CreditCard").respond([{id:{key:123}}]); + xhr.expectGET("/CreditCard/123").respond({id:{key:123}, number:'9876'}); + var ccs = CreditCard.query(); + xhr.flush(); + expect(ccs.length).toEqual(1); + var cc = ccs[0]; + expect(cc instanceof CreditCard).toBeTruthy(); + expect(cc.number).not.toBeDefined(); + cc.$get(callback); + xhr.flush(); + expect(callback).wasCalledWith(cc); + expect(cc.number).toEqual('9876'); + }); + it("should update resource", function(){ xhr.expectPOST('/CreditCard/123', {id:{key:123}, name:'misko'}).respond({id:{key:123}, name:'rama'}); @@ -124,8 +139,8 @@ describe("resource", function() { it('should create on save', function(){ xhr.expectPOST('/CreditCard', {name:'misko'}).respond({id:123}); var cc = new CreditCard(); - expect(cc.$get).not.toBeDefined(); - expect(cc.$query).not.toBeDefined(); + expect(cc.$get).toBeDefined(); + expect(cc.$query).toBeDefined(); expect(cc.$remove).toBeDefined(); expect(cc.$save).toBeDefined(); -- cgit v1.2.3