-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Extend test coverage to sync relationships #409
Extend test coverage to sync relationships #409
Conversation
f72c9ec
to
5e9a874
Compare
d5a88af
to
6c1268a
Compare
I like this!! 👍 Happen to know why the two tests are failing? Also to confirm, there is no addon code changes needed right? |
After recent changes added in #404 those 2 tests started failing. It is caused by the fact that |
Great points! Yes you are right. A couple of points.
|
I merged the Array check #413 |
_internalModel is not a public API, so, it can be removed at any moment. I've asked for advice in the ED discord channel. |
@runspired suggested that we should ask the user if the object is an Ember Data Model or not. |
@andreyfel I like the idea of explicitly saying it is an EmberData object. However, this might get a little murky when an object's nested values are EmberData objects. A few thoughts.
The combination of these two (the second be always request the combination that leads to the leaf key) would alleviate all our problems, albeit, a stricter API. Do you have any thoughts? |
|
||
assert.equal(user.get('profile.firstName'), 'Bob', 'Profile is set on user'); | ||
assert.equal(user.get('dogs.firstObject.breed'), 'rough collie'); | ||
assert.equal(user.get('dogs.lastObject.breed'), 'Münsterländer'); |
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.
FYI I don't think these array accessors work (at the moment at least)
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.
Well, they work for EmberArray and dogs
is an EmberArray.
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.
Oh you are right...we are passing in Ember's getter...
Ember-changeset is supposed to work with sync and async relationships. Behavior differs significantly, we need to test for both types of relationships. Create `sync-user` model which is mirroring the `user` user model but it uses sync relationships. Refactor tests for users to be executable for both types of users.
In case of sync `profile` relationship user.profile is null after executing the changeset. For safe check we need to use `user.get('profile.firstName')` vs `user.get('profile').get('firstName')` user.get('profile') is always a proxy in case of async belongsTo(), and it doesn't correlate with calling `save()` on the user model. So, this check doesn't really check anything. For the sync relationship this check fails, because profile is null after performing `execute()`
Add more heuristics to support sync belongsTo() relationships. A preferable fix is to let user specify if an object is ED Model or not. One of the options is passing a flag in the constructor or having a separate implementation for ED Models.
6c1268a
to
897af38
Compare
@andreyfel Is this PR g2g? I'm happy with it in its current state as long as the latest master is merged in... |
Yes, I've rebased it today. The pr can be merged and we can think of refactoring after that. |
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.
Lovely! What a nice PR!
@snewcomer yesterday I wrote a comment but it appears I forgot to publish it. |
This PR extends test coverage for sync and async relationships.