Skip to content

Commit 587b9e8

Browse files
committed
Merge pull request #61 from creynders/fix_54
Fix tests for #54 and add missing ones for full coverage
2 parents cb27b58 + 35f7122 commit 587b9e8

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

backbone.geppetto.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@
8585
}
8686
},
8787

88-
createChildResolver: function() {
89-
var child = new Resolver(this._context);
90-
child.parent = this;
91-
return child;
92-
},
9388

9489
getObject: function(key) {
9590
return this._retrieveFromCacheOrCreate(key, false);
@@ -185,12 +180,14 @@
185180

186181
if (this.options.resolver) {
187182
this.resolver = this.options.resolver;
188-
} else if (this.parentContext) {
189-
this.resolver = this.parentContext.resolver.createChildResolver();
190183
} else if (!this.resolver) {
191184
this.resolver = new Resolver(this);
192185
}
193186

187+
if (this.parentContext) {
188+
this.resolver.parent = this.parentContext.resolver;
189+
}
190+
194191
this.vent = {};
195192
_.extend(this.vent, Backbone.Events);
196193
this._contextId = _.uniqueId("Context");

specs/src/geppetto-specs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ define([
5757
expect(stub).to.have.been.calledOnce;
5858
});
5959
});
60+
it("should use the optionally provided resolver", function(){
61+
var child = new Geppetto.Context({
62+
resolver: context.resolver
63+
});
64+
expect(child.resolver).to.equal(context.resolver);
65+
child.destroy();
66+
});
6067
});
6168

6269
describe("when binding a context to a view that does not support dependency injection", function() {
@@ -723,6 +730,7 @@ define([
723730

724731
it("should have an resolver which is a child resolver of the parent", function() {
725732
expect(childContext.resolver.parent).to.equal(parentContext.resolver);
733+
expect(childContext.resolver).not.to.equal(parentContext.resolver);
726734
});
727735

728736
});
@@ -847,6 +855,7 @@ define([
847855
var context;
848856

849857
beforeEach(function() {
858+
850859
var viewDef = Backbone.View.extend();
851860
view = new viewDef();
852861
context = Geppetto.bindContext({

specs/src/resolver-specs.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ define([
6060
});
6161
});
6262
describe("when retrieving objects", function() {
63+
it("should poll the parent resolver if no corresponding mapping was found", function(){
64+
var value = {};
65+
var child = new Geppetto.Context({
66+
parentContext : context
67+
});
68+
resolver.wireValue('value', value);
69+
var actual = child.resolver.getObject('value');
70+
expect(actual).to.equal(value);
71+
});
6372
it("should throw an error if no corresponding mapping was found", function() {
6473
expect(function() {
6574
resolver.getObject('unregistered key');
@@ -338,31 +347,6 @@ define([
338347
throw (/no mapping found/);
339348
});
340349
});
341-
describe("when creating childResolvers", function() {
342-
var parent, child;
343-
var key1 = 'key 1';
344-
var value1 = {};
345-
var key2 = 'key 2';
346-
var value2 = {};
347-
beforeEach(function() {
348-
parent = new Geppetto.Resolver(context);
349-
parent.wireValue(key1, value1);
350-
child = parent.createChildResolver();
351-
child.wireValue(key2, value2);
352-
});
353-
it("should populate the child's parent property", function() {
354-
expect(child.parent).to.equal(parent);
355-
});
356-
it("should allow to retrieve objects mapped to the parent through the child", function() {
357-
expect(child.getObject(key1)).to.equal(value1);
358-
});
359-
it("should not allow to retrieve objects mapped to the child through the parent", function() {
360-
expect(function() {
361-
parent.getObject(key2);
362-
}).to.
363-
throw (/no mapping found/);
364-
});
365-
});
366350
describe('when used with Backbone objects', function(){
367351
var clazzInstantiated;
368352
var clazz = function(){

0 commit comments

Comments
 (0)