-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Fixes #4807] realize class + factory seperation #4810
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do
Ember.deprecate
instead of the TODO?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't currently have a path forward yet. I would prefer to deprecate once this is the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But will find a path forward for this soon!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chadhietala I'm doing a follow up PR (right now) that reduces ember-datas dependence on
modelName
. That will be a pre-cursor to deprecating it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SG
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've removed many more internal usages of
modelName
, there are some more low hanging fruit but addressing it fully will be some effort (although I hope we can do asap).Some notes: #4814