Skip to content

Commit

Permalink
Moves the Integrated Container logic up to TestModule
Browse files Browse the repository at this point in the history
  • Loading branch information
nikz committed Mar 12, 2015
1 parent 06ff474 commit 5983dfd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
21 changes: 3 additions & 18 deletions lib/ember-test-helpers/test-module-for-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { getResolver } from './test-resolver';
import { getContext, setContext } from './test-context';

export default TestModule.extend({

isIntegration: true,

init: function(name, description, callbacks) {
this._super.call(this, name, description, callbacks);
this.setupSteps.push(this.setupIntegrationHelpers);
Expand Down Expand Up @@ -55,24 +58,6 @@ export default TestModule.extend({

},

setupContainer: function() {
var resolver = getResolver();
var namespace = Ember.Object.create({
Resolver: { create: function() { return resolver; } }
});

if (Ember.Application.buildRegistry) {
var registry;
registry = Ember.Application.buildRegistry(namespace);
registry.register('component-lookup:main', Ember.ComponentLookup);
this.registry = registry;
this.container = registry.container();
} else {
this.container = Ember.Application.buildContainer(namespace);
this.container.register('component-lookup:main', Ember.ComponentLookup);
}
},

setupContext: function() {

setContext({
Expand Down
36 changes: 35 additions & 1 deletion lib/ember-test-helpers/test-module.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Ember from 'ember';
import isolatedContainer from './isolated-container';
import { getContext, setContext } from './test-context';
import { Klass } from 'klassy';
import { getResolver } from './test-resolver';

export default Klass.extend({
init: function(subjectName, description, callbacks) {
Expand All @@ -16,6 +18,10 @@ export default Klass.extend({
this.name = description || subjectName;
this.callbacks = callbacks || {};

if (this.callbacks.integration) {
this.isIntegration = callbacks.integration;
}

this.initSubject();
this.initNeeds();
this.initSetupSteps();
Expand Down Expand Up @@ -97,7 +103,11 @@ export default Klass.extend({
},

setupContainer: function() {
this.container = isolatedContainer(this.needs);
if (this.isIntegration) {
this._setupIntegratedContainer();
} else {
this._setupIsolatedContainer();
}
},

setupContext: function() {
Expand Down Expand Up @@ -184,6 +194,30 @@ export default Klass.extend({

})(keys[i]);
}
},


_setupIsolatedContainer: function() {
this.container = isolatedContainer(this.needs);
},

_setupIntegratedContainer: function() {
var resolver = getResolver();
var namespace = Ember.Object.create({
Resolver: { create: function() { return resolver; } }
});

if (Ember.Application.buildRegistry) {
var registry;
registry = Ember.Application.buildRegistry(namespace);
registry.register('component-lookup:main', Ember.ComponentLookup);
this.registry = registry;
this.container = registry.container();
} else {
this.container = Ember.Application.buildContainer(namespace);
this.container.register('component-lookup:main', Ember.ComponentLookup);
}
}

});

13 changes: 12 additions & 1 deletion tests/test-module-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function moduleFor(fullName, description, callbacks) {

function setupRegistry() {
setResolverRegistry({
'component:x-foo': Ember.Component.extend()
'component:x-foo': Ember.Component.extend(),
'component:not-the-subject': Ember.Component.extend()
});
}

Expand Down Expand Up @@ -123,3 +124,13 @@ moduleFor('component:x-foo', 'component:x-foo -- uncreated subjects do not error
test("subject's created in a test are destroyed", function() {
expect(0);
});

moduleFor('component:x-foo', 'component:x-foo -- `integration: true`', {
beforeSetup: setupRegistry(),
integration: true
});

test("needs is not needed (pun intended) when integration is true", function() {
var otherComponent = this.container.lookup('component:not-the-subject');
ok(otherComponent, 'another component can be resolved when integration is true');
});

0 comments on commit 5983dfd

Please sign in to comment.