Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move integration container logic to TestModule #24

Merged
merged 2 commits into from
Mar 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
37 changes: 36 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,11 @@ export default Klass.extend({
this.name = description || subjectName;
this.callbacks = callbacks || {};

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

this.initSubject();
this.initNeeds();
this.initSetupSteps();
Expand Down Expand Up @@ -97,7 +104,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 +195,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);
}
}

});

36 changes: 35 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,36 @@ 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 -- without needs or `integration: true`', {
beforeSetup: setupRegistry()
});

test("knows nothing about our non-subject component", function() {
var otherComponent = this.container.lookup('component:not-the-subject');
equal(null, otherComponent, "We shouldn't know about a non-subject component")
});

moduleFor('component:x-foo', 'component:x-foo -- when needing another component', {
beforeSetup: setupRegistry(),
needs: ['component:not-the-subject']
});

test("needs gets us the component we need", function() {
var otherComponent = this.container.lookup('component:not-the-subject');
ok(otherComponent, "another component can be resolved when it's in our needs array");
});

moduleFor('component:x-foo', 'component:x-foo -- `integration: true`', {
beforeSetup: function() {
setupRegistry()
ok(!this.callbacks.integration, "integration property should be removed from callbacks");
ok(this.isIntegration, "isIntegration should be set when we set `integration: true` in callbacks");
},
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');
});