diff options
| author | Misko Hevery | 2010-10-08 17:30:13 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-10-12 16:33:06 -0700 |
| commit | d9abfe8a7e488be8725f56077527b16f7c79546a (patch) | |
| tree | 67089c5d2059e7a56afab0fec19dbce76fdab798 /test/ResourceSpec.js | |
| parent | fbfd160316de1b99e7afa4102c7fae2ee5b9c1f5 (diff) | |
| download | angular.js-d9abfe8a7e488be8725f56077527b16f7c79546a.tar.bz2 | |
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject
- inject method can return, instance, or call function which have $inject
property
- initialize services with $creation=[eager|eager-publish] this means that
only some of the services are now globally accessible
- upgraded $become on scope to use injector hence respect the $inject property
for injection
- $become should not be run multiple times and will most likely be removed
in future version
- added $new on scope to create a child scope
- $inject is respected on constructor function
- simplified scopes so that they no longer have separate __proto__ for
parent, api, behavior and instance this should speed up execution since
scope will now create one __proto__ chain per scope (not three).
BACKWARD COMPATIBILITY WARNING:
- services now need to have $inject instead of inject property for proper
injection this breaks backward compatibility
- not all services are now published into root scope
(only: $location, $cookie, $window)
- if you have widget/directive which uses services on scope
(such as this.$xhr), you will now have to inject that service in
(as it is not published on the root scope anymore)
Diffstat (limited to 'test/ResourceSpec.js')
| -rw-r--r-- | test/ResourceSpec.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 435176b0..e258d5a3 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -162,26 +162,30 @@ describe("resource", function() { it('should excersize full stack', function(){ var scope = angular.compile('<div></div>'); - var Person = scope.$resource('/Person/:id'); - scope.$browser.xhr.expectGET('/Person/123').respond('\n{\nname:\n"misko"\n}\n'); + var $browser = scope.$inject('$browser'); + var $resource = scope.$inject('$resource'); + var Person = $resource('/Person/:id'); + $browser.xhr.expectGET('/Person/123').respond('\n{\nname:\n"misko"\n}\n'); var person = Person.get({id:123}); - scope.$browser.xhr.flush(); + $browser.xhr.flush(); expect(person.name).toEqual('misko'); }); it('should return the same object when verifying the cache', function(){ var scope = angular.compile('<div></div>'); - var Person = scope.$resource('/Person/:id', null, {query: {method:'GET', isArray: true, verifyCache: true}}); - scope.$browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"misko"\n}\n]'); + var $browser = scope.$inject('$browser'); + var $resource = scope.$inject('$resource'); + var Person = $resource('/Person/:id', null, {query: {method:'GET', isArray: true, verifyCache: true}}); + $browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"misko"\n}\n]'); var person = Person.query({id:123}); - scope.$browser.xhr.flush(); + $browser.xhr.flush(); expect(person[0].name).toEqual('misko'); - scope.$browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"rob"\n}\n]'); + $browser.xhr.expectGET('/Person/123').respond('[\n{\nname:\n"rob"\n}\n]'); var person2 = Person.query({id:123}); expect(person2[0].name).toEqual('misko'); var person2Cache = person2; - scope.$browser.xhr.flush(); + $browser.xhr.flush(); expect(person2Cache).toEqual(person2); expect(person2[0].name).toEqual('rob'); }); |
