Change _normalizeTypeKey to defer normalization to the container #1
+27
−4
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 are some failing tests and some additional work to do.
The issue is that in unit tests for ember-cli for models with dashes and
when using an adapter, the model's typeKey is normalized to camelCase
but
store.modelFor(camelCasedName)
will fail.For example, with a model class 'ssh-key', create a record using the
string 'ssh-key'. This will work fine because the store will call
modelFor('ssh-key')
. This returns the correct model factory and it has the side effect of settingtypeKey
on that factory tosshKey
.Later, when saving that record, the store will call
Adapter.createRecord
which starts out by callingstore.serializerFor(type.typeKey)
. The store'sserializerFor
method passes this same typeKey (sshKey
) tostore.modelFor
. Butstore.modelFor('sshKey')
will fail because it will callcontainer.lookupFactory('model:sshKey')
and find nothing.The call to
lookupFactory('model:sshKey')
will fail in the test because the test's container'snormalizeFullName
method is this:When running an ember-cli normally (or when running an acceptance test), the container uses the ember-cli resolver and its
normalizeFullName
method becomes this:In this case,
resolver.normalize
will return the same value ("model:ssh-key"
) when it is passed either"model:sshKey"
or"model:ssh-key"
, so the app'sstore.modelFor('sshKey')
andstore.modelFor('ssh-key')
return the same thing.There's a sample ember-cli app showing this behavior. The important parts are in this commit. The failing test code looks like this:
Screenshot of the failing test in the ember-cli app:

cc @mixonic