-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fixes #4807] realize class + factory seperation
*note: this combined with embers factoryFor makes `MODEL_FACTORY_INJECTIONS` irrelevant.*
- Loading branch information
1 parent
e2f35a7
commit 314ae0b
Showing
6 changed files
with
1,238 additions
and
1,206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import setupStore from 'dummy/tests/helpers/store'; | ||
import Ember from 'ember'; | ||
import DS from 'ember-data'; | ||
import { module, test } from 'qunit'; | ||
|
||
let env, originalFactoryFor, originalMODEL_FACTORY_INJECTIONS = Ember.MODEL_FACTORY_INJECTIONS; | ||
const { run } = Ember; | ||
|
||
const factory = { | ||
isFactory: true, | ||
class: { | ||
isModel: true, | ||
_create() { } | ||
} | ||
}; | ||
|
||
module('integration/injection factoryFor enabled', { | ||
setup() { | ||
env = setupStore(); | ||
|
||
originalFactoryFor = Ember.getOwner(env.store).factoryFor; | ||
|
||
Ember.getOwner(env.store).factoryFor = function(name) { | ||
return factory; | ||
}; | ||
}, | ||
|
||
teardown() { | ||
Ember.getOwner(env.store).factoryFor = originalFactoryFor; | ||
|
||
run(env.store, 'destroy'); | ||
} | ||
}); | ||
|
||
test('modelFactoryFor', function(assert) { | ||
const modelFactory = env.store.modelFactoryFor('super-villain'); | ||
|
||
assert.equal(modelFactory, factory, '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'); | ||
|
||
// 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'); | ||
}); | ||
|
||
module('integration/injection eager injections', { | ||
setup() { | ||
Ember.MODEL_FACTORY_INJECTIONS = true; | ||
env = setupStore(); | ||
|
||
env.registry.injection('model:foo', 'apple', 'service:apple'); | ||
env.registry.register('model:foo', DS.Model); | ||
env.registry.register('service:apple', Ember.Object.extend({ isService: true })); | ||
// container injection | ||
}, | ||
|
||
teardown() { | ||
// can be removed once we no longer support ember versions without lookupFactory | ||
Ember.MODEL_FACTORY_INJECTIONS = originalMODEL_FACTORY_INJECTIONS; | ||
|
||
run(env.store, 'destroy'); | ||
} | ||
}); | ||
|
||
test('did inject', function(assert) { | ||
let foo = run(() => env.store.createRecord('foo')); | ||
let apple = foo.get('apple'); | ||
let Apple = env.registry.registrations['service:apple']; | ||
|
||
assert.ok(apple, `'model:foo' instance should have an 'apple' property`); | ||
assert.ok(apple instanceof Apple, `'model:foo'.apple should be an instance of 'service:apple'`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.