-
Notifications
You must be signed in to change notification settings - Fork 19
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
Improve test setup #92
Improve test setup #92
Conversation
…ype from toString()
@@ -116,7 +116,7 @@ const Resource = Ember.Object.extend(ResourceOperationsMixin, { | |||
@method toString | |||
*/ | |||
toString() { | |||
let type = this.get('type') || 'null'; | |||
let type = singularize(this.get('type')) || 'null'; |
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 makes toStrings more predictable and easier to test.
Cleans and improves some/most tests. Replaces a lot of handwritten strings ( Adds actual calling of Uses models defined in dummy app (I'm not sure if I broke that dummy app with the changes in models. Haven't looked at that yet). |
const adapter = this.subject({type: 'posts', url: '/posts'}); | ||
sandbox.stub(adapter, 'fetch', function () { return RSVP.Promise.resolve(null); }); | ||
let resource = this.container.lookup('model:post').create(postMock.data); | ||
sandbox.stub(adapter, 'cacheRemove', function () {}); | ||
Ember.run(function() { | ||
Ember.run(() => { // Why is this called inside a Ember RunLoop? Does that imply async? |
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 forget when I needed the run loop, but typically I'm expecting some backburner
queues to be processed.
I'm pretty sure it was to be sure https://github.com/pixelhandler/ember-jsonapi-resources/blob/master/addon/adapters/application.js#L188 resource.destroy();
is completed.
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.
Since theoretically stuff could break within the runloop I'll use another assert.expect()
and async()
here so we know when it does.
@aars I like the changes. I replied to a few questions in the code comments. All the tests pass, (using ember try as well). Perhaps we merge in after addressing the questions in the code comments. |
@pixelhandler Replies and updates. Will continue with other tests now. Please have a look at my changes to I ended up not even testing for |
@pixelhandler Regarding casting ids to strings. If I could direct your attention at this code, written by you: https://github.com/pixelhandler/ember-jsonapi-resources/blob/master/tests/unit/mixins/resource-operations-test.js It uses numbers as ids everywhere. You use it consistently in this file, so no test is broken... but... this is incorrect usage of the lib/spec, in your lib, by you. It will break as soon as you, per spec, try to look up a relation by id using a string. Can I use this to strengthen my argument about easy pitfalls and annoying users? 😝 PS: The code in this test creates invalid JSONAPI payloads to the server as well, since ids are never transformed. |
@aars when we cast to string for fetching, we should also cast to string when we deserialize too. |
if (options.id) { | ||
return this.findOne(options.id, options.query); | ||
// Collect id and query from options (if given). | ||
// ids are cast to string to allow number input. |
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.
perhaps instead of "to allow" we could say to "ensure id is a Strings (which spec requires)"
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.
Many better.
@pixelhandler Casting to string when deserializing is on the other side of "the spectrum" though, as in; the current goal is to improve JSONAPI compliancy for "users" of this library, programmers (people) who feed it data, where mistakes like numerical ids can easily happen. On the other side is the server, which should never have sent a numerical id to begin with. If we're casting to string when deserializing we're only adding in support for broken JSONAPI endpoints... No? What do you think? Not that I'm really against it. I would however add a warning message about the server sending invalid payloads (edit: I am now against it! 😄 see some line comment) |
@@ -189,6 +221,10 @@ test('#findRelated', function(assert) { | |||
}); | |||
}); | |||
|
|||
// TODO: This test is broken in an odd fashion. Ends up somehow calling `addRelationship` |
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 was addressed in PR #94
@aars casting in Here is where the deserialization begins, https://github.com/pixelhandler/ember-jsonapi-resources/blob/master/addon/mixins/fetch.js#L148-L150 And in the serializer we could add an assert for the id type in here https://github.com/pixelhandler/ember-jsonapi-resources/blob/master/addon/serializers/application.js#L208-L233 but seems fine to just trust that the server is doing it's part. |
I'm on my second sip of coffee, I wasn't fully awake when I wrote about deserialize supporting broken servers. Still am not, but as you noticed and commented, the casting to string in |
…ype from toString()
I have rebased/merged. I will squash the commits later today. edit: I'm having a horrible time rebasing/squashing this. Can we consider this PR and commit history for merging? If you prefer these commits squash I'll cherry-pick them on a new branch and create a new PR. |
…ts. Improves comment
When all is 🎉 I have this PR ready to fix/improve working with relationship resource types: realxsnl#1 (goes on top of this PR). |
@aars there is a "Squash and merge" option so I can just do that, no need for you to squash. |
This PR is intended to review/discuss changes.