Skip to content

Commit

Permalink
Fix tests in release branch RE: factoryFor. (#4878)
Browse files Browse the repository at this point in the history
* Update test suite to test 2.4 and 2.8 LTS's.

* Ensure factoryFor related tests pass on release branch.

Adds various conditionals and updates assertions to match
expectations for each of 1.13, 2.4, 2.8, and 2.12.
  • Loading branch information
rwjblue authored and bmac committed Mar 17, 2017
1 parent 2f82ad1 commit ba7f462
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 14 deletions.
43 changes: 43 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ module.exports = {
resolutions: {
'ember': '1.13.13'
}
},
npm: {
'ember-source': null
}
},
{
name: 'ember-2-4',
bower: {
dependencies: {
'ember': '~2.4.0'
},
resolutions: {
'ember': '~2.4.0'
}
},
npm: {
'ember-source': null
}
},
{
name: 'ember-2-8',
bower: {
dependencies: {
'ember': '~2.8.0'
},
resolutions: {
'ember': '~2.8.0'
}
},
npm: {
'ember-source': null
}
},
{
Expand All @@ -27,6 +58,9 @@ module.exports = {
resolutions: {
'ember': 'release'
}
},
npm: {
'ember-source': null
}
},
{
Expand All @@ -38,6 +72,9 @@ module.exports = {
resolutions: {
'ember': 'beta'
}
},
npm: {
'ember-source': null
}
},
{
Expand All @@ -49,6 +86,9 @@ module.exports = {
resolutions: {
'ember': 'canary'
}
},
npm: {
'ember-source': null
}
},
{
Expand All @@ -60,6 +100,9 @@ module.exports = {
resolutions: {
'ember': 'alpha'
}
},
npm: {
'ember-source': null
}
}
]
Expand Down
58 changes: 44 additions & 14 deletions tests/integration/injection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,60 @@ import Ember from 'ember';
import DS from 'ember-data';
import { module, test } from 'qunit';

let env, originalFactoryFor, originalMODEL_FACTORY_INJECTIONS = Ember.MODEL_FACTORY_INJECTIONS;
let env, hasFactoryFor, originalLookupFactory, originalOwnerLookupFactory, originalFactoryFor;
let originalMODEL_FACTORY_INJECTIONS = Ember.MODEL_FACTORY_INJECTIONS;
const { run } = Ember;

const model = {
isModel: true,
_create() { }
};
const factory = {
isFactory: true,
class: {
isModel: true,
_create() { }
}
class: model
};

module('integration/injection factoryFor enabled', {
setup() {
env = setupStore();

originalFactoryFor = Ember.getOwner(env.store).factoryFor;

Ember.getOwner(env.store).factoryFor = function(name) {
return factory;
};
if (Ember.getOwner) {
let owner = Ember.getOwner(env.store);

hasFactoryFor = !!owner.factoryFor;
originalFactoryFor = owner.factoryFor;
originalOwnerLookupFactory = owner._lookupFactory;

if (originalFactoryFor) {
owner.factoryFor = function(/* name */) {
return factory;
};
} else {
// Ember 2.3 - Ember 2.11
originalOwnerLookupFactory = owner._lookupFactory;
owner._lookupFactory = function() {
return model;
};
}
} else {
originalLookupFactory = env.store.container.lookupFactory;
env.store.container.lookupFactory = function() {
return model;
};
}
},

teardown() {
Ember.getOwner(env.store).factoryFor = originalFactoryFor;
if (Ember.getOwner) {
let owner = Ember.getOwner(env.store);

if (owner.factoryFor) {
owner.factoryFor = originalFactoryFor;
} else {
owner._lookupFactory = originalOwnerLookupFactory;
}
} else {
env.store.container.lookupFactory = originalLookupFactory;
}

run(env.store, 'destroy');
}
Expand All @@ -35,13 +65,13 @@ module('integration/injection factoryFor enabled', {
test('modelFactoryFor', function(assert) {
const modelFactory = env.store.modelFactoryFor('super-villain');

assert.equal(modelFactory, factory, 'expected the factory itself to be returned');
assert.equal(modelFactory, hasFactoryFor ? factory : model, 'expected the factory itself to be returned');
});

test('modelFor', function(assert) {
const modelFactory = env.store.modelFor('super-villain');

assert.equal(modelFactory, factory.class, 'expected the factory itself to be returned');
assert.equal(modelFactory, model, 'expected the factory itself to be returned');

// TODO: we should deprecate this next line. Resolved state on the class is fraught with peril
assert.equal(modelFactory.modelName, 'super-villain', 'expected the factory itself to be returned');
Expand Down

0 comments on commit ba7f462

Please sign in to comment.