Skip to content

Commit b2d91ff

Browse files
authored
Merge pull request #21 from onumossn/transformJsonapiAttrs
transformJsonapiAttrs
2 parents 3ddff17 + 95a927e commit b2d91ff

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

addon/mixins/nested-relations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const attributesFor = function(record) {
5151
}
5252
});
5353

54-
return attrs;
54+
return record.transformJsonapiAttrs ? record.transformJsonapiAttrs(attrs) : attrs;
5555
};
5656

5757
const jsonapiPayload = function(record, relationshipMarkedForDeletion) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-data-jsonapi-extensions",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"description": "The default blueprint for ember-cli addons.",
55
"directories": {
66
"doc": "doc",

tests/unit/mixins/nested-relations-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,31 @@ test('it serializes basic attributes correctly', function(assert) {
153153
assert.deepEqual(json, expectedJSON, 'has correct json');
154154
});
155155

156+
test('it uses transformJsonapiAttrs to modify attributes', function(assert) {
157+
let post = store.createRecord('post', { title: 'test post' });
158+
159+
post.transformJsonapiAttrs = function(attrs) {
160+
return {
161+
titleUpcase: attrs.title.toUpperCase(),
162+
publishedDate: this.get('publishedDate')
163+
};
164+
};
165+
166+
let json = serialize(post, {});
167+
168+
let expectedJSON = {
169+
data: {
170+
type: 'posts',
171+
attributes: {
172+
titleUpcase: 'test post'.toUpperCase(),
173+
publishedDate: post.get('publishedDate')
174+
}
175+
}
176+
};
177+
178+
assert.deepEqual(json, expectedJSON, 'has correct json');
179+
});
180+
156181
test('it respects custom keyForAttribute settings in serializer', function(assert) {
157182
let date = new Date();
158183
let post = store.createRecord('post', { publishedDate: date });

0 commit comments

Comments
 (0)