-
Notifications
You must be signed in to change notification settings - Fork 441
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
refactor(ember-5): access Ember Models via Store #2502
refactor(ember-5): access Ember Models via Store #2502
Conversation
c583c4f
to
b696a21
Compare
b696a21
to
67553ed
Compare
@Pixelik sorry for delay here, do you mind to refresh branch with latest |
Hello. It all looks green to me and up-to-date, ready to be merged 🤔 |
branch of this PR is outdated and although the PR status is green, it has no job runs in "Checks" tab. Anyways, I've created a unit test which uses Hence, for |
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.
this actually does not work, see CI run https://github.com/miragejs/ember-cli-mirage/actions/runs/6193523102
@SergeAstapov where is this test defined ? I can't find it in this branch 🤔 Do you have a link to that file ? (But it makes sense that such a test would fail as this PR is changing the way tests are discovered) |
@Pixelik there is no such test in master now and this PR does not add anything. @Pixelik please see https://github.com/miragejs/ember-cli-mirage/pull/2528/files#diff-a16b283fd8b39b8decc1f1e8824d3a777dca6c861c511f6999ace605541c8807 where test added |
@SergeAstapov |
@Pixelik well, yes. but how can we guarantee that it will be present by the time |
If I understand ember |
I have already tried my solution in my app and it works by the way, but obviously this, by itself, is not good enough of a proof that it will always work, I'm just mentioning this as a side note. |
@Pixelik sounds like this limitation needs to be documented then? |
Perhaps. Is it possible that someone would try to EDIT: Well I guess only if they invoke this method during their Unit tests.. |
But yes, documenting this sounds necessary to me now as well. |
Sorry for being late to the party but I would think that autoDiscoverDataModels should be passed the store. In setupMirage the this.owner is passed into startMirage (so if startMirage is called outside tests, this is a required param). https://github.com/miragejs/ember-cli-mirage/blob/master/packages/ember-cli-mirage/addon-test-support/setup-mirage.js#L23, so it will be accessible (Quick aside, makeServer can be passed as an option on SetupMirage and passed into StartMirage)
then in startMirage, if one is passed, it uses it, if not looks it up. https://github.com/miragejs/ember-cli-mirage/blob/master/packages/ember-cli-mirage/addon/start-mirage.js#L21 (This look up is what was prepped in one of the initializers. I would love to see a mandate of passing it in, then could remove one of the intializers). This also has the benefit of specifying different configs for different tests if needed, or a different config for dev vs test. hence why testConfig is no longer needed. You could lookup the store and add it here https://github.com/miragejs/ember-cli-mirage/blob/master/packages/ember-cli-mirage/addon/start-mirage.js#L29 or add owner here and require them to look it. Either way you now have a store that you could pass into autoDiscoverDataModels which might be more straight forward and intuitive. Supports multiple stores if someone did have them, plus you dont depend on the initializer for |
Thank you @cah-brian-gantzler and @Pixelik for ideas and discussion! I've landed fix in #2542 |
Refactor
Instead of accessing a Model with:
It will now be accessed with: