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

Fix bug where not all meta data is omitted during serialisation #4

Merged
merged 2 commits into from
Feb 1, 2017
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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vry",
"version": "2.0.0",
"version": "2.0.1",
"description": "Define `Model` and `Collection` like types to manage your `Immutable` data structures in a functional way",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ internals.serialize = function(model, options) {
if (!omitMeta) {
return partial.toJS();
} else {
return partial.filter((value, key) => key !== Props.cid).toJS();
return partial.filter((value, key) => key !== Props.cid && key !== Props.name).toJS();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internals.serialize = (state, optionsOrOmit) => {
if (!omitMeta) {
return state.toJS();
} else {
return state.filter((value, key) => key !== internals.props.cid).toJS();
return state.filter((value, key) => key !== internals.props.cid && key !== internals.props.name).toJS();
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Test('model.schema', function(t) {
})

Test('model.serialize', function(t) {
t.plan(15 + 3 + 2 + 2)
t.plan(16 + 3 + 2 + 2)

const OtherModel = Model.create({
typeName: 'woo'
Expand Down Expand Up @@ -326,6 +326,7 @@ Test('model.serialize', function(t) {
t.ok(_.isArray(serialized.nestedSet), 'nested Sets are serialized as arrays')
t.ok(_.isArray(serialized.nestedOrderedSet), 'nested OrderedSets are serialized as arrays')
t.ok(_.isUndefined(serialized.__cid), 'the client side identifier is omitted by default')
t.ok(_.isUndefined(serialized.__typeName), 'the model type name is omitted by default')
}, 'accepts a model instance')

t.doesNotThrow(() => {
Expand Down
4 changes: 3 additions & 1 deletion test/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Test('state.collectionOf', function(t) {
});

Test('state.serialize', function(t) {
t.plan(7 + 3 + 2 + 2);
t.plan(7 + 5 + 2 + 2);

var state = State.create('test-model', {});

Expand Down Expand Up @@ -257,7 +257,9 @@ Test('state.serialize', function(t) {
var serializedIncluded = state.serialize(instance, { omitMeta: false });

t.ok(_.isUndefined(serialized.__cid), 'serialized object does not contain cid by default');
t.ok(_.isUndefined(serialized.__typeName), 'serialized object does not contain typename by default');
t.equal(instance.get('__cid'), serializedIncluded.__cid, 'serialized object contains the client identifier of the instance when passing true for the `omitMeta` option');
t.equal(instance.get('__typeName'), serializedIncluded.__typeName, 'serialized object contains the state type name of the instance when passing true for the `omitMeta` option')
}, 'accepts a State instance and options with a flag to omit meta data');

t.doesNotThrow(function() {
Expand Down