Skip to content

Commit

Permalink
update mockUpdate to only return data if there are return args
Browse files Browse the repository at this point in the history
  • Loading branch information
danielspaniel committed Dec 17, 2017
1 parent c47fea0 commit 1e06d93
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions addon/mocks/mock-update-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ export default class MockUpdateRequest extends MaybeIdUrlMatch(AttributeMatcher(

/**
This returns only accepts attrs key
These attrs are those attributes or relationships that
you would like returned with the model when the update succeeds.
You can't user returns if you use mockUpdate with only a modelName like:
mockUpdate('user'); ( no id specified )
@param {Object} returns attributes and or relationships to send with payload
*/
returns(returns) {
Expand All @@ -57,14 +61,16 @@ export default class MockUpdateRequest extends MaybeIdUrlMatch(AttributeMatcher(
}

/**
Adapters freak out if update payload is non empty response with no id.
So, if there is no id specified for this update => return null
Adapters freak out if update payload is non empty and there is no id.
So, if you use mockUpdate like this:
mockUpdate('user'); ( no id specified ) this mock will return null
@returns {*}
*/
getResponse() {
this.responseJson = null;
if (this.id) {
if (Object.keys(this.returnArgs).length) {
let args = assign({}, this.matchArgs, this.returnArgs),
json = assign({}, args, {id: this.id});
this.responseJson = this.fixtureBuilder.convertForBuild(this.modelName, json);
Expand Down

0 comments on commit 1e06d93

Please sign in to comment.