Skip to content

Commit

Permalink
Merge pull request #4311 from balinterdi/use-property-lookup-in-apply…
Browse files Browse the repository at this point in the history
…-transforms

Use property lookup in applyTransforms
  • Loading branch information
bmac committed May 23, 2016
2 parents 0e15f2f + a2bd7db commit b3cbfb7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion addon/serializers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var JSONSerializer = Serializer.extend({
let attributes = get(typeClass, 'attributes');

typeClass.eachTransformedAttribute((key, typeClass) => {
if (!(key in data)) { return; }
if (data[key] === undefined) { return; }

var transform = this.transformFor(typeClass);
var transformMeta = attributes.get(key);
Expand Down
11 changes: 2 additions & 9 deletions tests/unit/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,26 +925,23 @@ AssertionPrototype.convertsWhenSet = function(type, provided, expected) {
};

test("a DS.Model can describe String attributes", function(assert) {
assert.expect(6);
assert.expect(4);

assert.converts('string', "Scumbag Tom", "Scumbag Tom");
assert.converts('string', 1, "1");
assert.converts('string', "", "");
assert.converts('string', null, null);
assert.converts('string', undefined, null);
assert.convertsFromServer('string', undefined, null);
});

test("a DS.Model can describe Number attributes", function(assert) {
assert.expect(9);
assert.expect(8);

assert.converts('number', "1", 1);
assert.converts('number', "0", 0);
assert.converts('number', 1, 1);
assert.converts('number', 0, 0);
assert.converts('number', "", null);
assert.converts('number', null, null);
assert.converts('number', undefined, null);
assert.converts('number', true, 1);
assert.converts('number', false, 0);
});
Expand All @@ -957,18 +954,14 @@ test("a DS.Model can describe Boolean attributes", function(assert) {

if (isEnabled('ds-boolean-transform-allow-null')) {
assert.converts('boolean', null, null, { allowNull: true });
assert.converts('boolean', undefined, null, { allowNull: true });

assert.converts('boolean', null, false, { allowNull: false });
assert.converts('boolean', undefined, false, { allowNull: false });

// duplicating the tests from the else branch here, so once the feature is
// enabled and the else branch is deleted, those assertions are kept
assert.converts('boolean', null, false);
assert.converts('boolean', undefined, false);
} else {
assert.converts('boolean', null, false);
assert.converts('boolean', undefined, false);
}

assert.converts('boolean', true, true);
Expand Down

0 comments on commit b3cbfb7

Please sign in to comment.