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

Ensure moduleForModel uses the correct store for subject. #28

Merged
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
4 changes: 4 additions & 0 deletions lib/ember-test-helpers/test-module-for-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ export default TestModule.extend({
}

callbacks.store = function(){
var container = this.container;

return container.lookup('store:main');
};

if (callbacks.subject === defaultSubject) {
callbacks.subject = function(options) {
var container = this.container;

return Ember.run(function() {
return container.lookup('store:main').createRecord(modelName, options);
});
Expand Down
37 changes: 34 additions & 3 deletions tests/test-module-for-model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,38 @@ function setupRegistry() {

///////////////////////////////////////////////////////////////////////////////

var store1, store2;
moduleForModel('whazzit', 'model:whazzit without adapter', {
beforeSetup: function() {
setupRegistry();
},

setup: function() {
Whazzit.FIXTURES = [];
},

teardown: function() {
if (store1 && store2) {
notEqual(store1, store2, 'store should be separate between tests');
}
}
});

test('store exists', function() {
var store = this.store();
ok(store instanceof DS.Store);
test('store exists: 1', function() {
store1 = this.store();

ok(store1 instanceof DS.Store);
});

test('store exists: 2', function() {
store2 = this.store();

ok(store2 instanceof DS.Store);
});

test('model exists as subject', function() {
var model = this.subject();

ok(model);
ok(model instanceof DS.Model);
ok(model instanceof Whazzit);
Expand All @@ -59,6 +74,22 @@ test('FixtureAdapter is registered for model', function() {
ok(!(store.adapterFor(model.constructor) instanceof WhazzitAdapter));
});

moduleForModel('whazzit', 'subject does not share the store', {
beforeSetup: function() {
setupRegistry();
},

teardown: function() {
var model = this.subject();
var store = this.store();

equal(model.store, store, 'is created from the correct store instance');
}
});

test('first subject test', function() { });
test('second subject test', function() { });

///////////////////////////////////////////////////////////////////////////////

moduleForModel('whazzit', 'model:whazzit with custom adapter', {
Expand Down