Skip to content
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

Use property lookup in applyTransforms #4311

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/serializers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export default Serializer.extend({
}

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

var transform = this.transformFor(typeClass);
if (isEnabled('ds-transform-pass-options')) {
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 @@ -906,26 +906,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 @@ -938,18 +935,14 @@ test("a DS.Model can describe Boolean attributes", function(assert) {

if (isEnabled('ds-transform-pass-options') && 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