Skip to content

Commit

Permalink
Merge pull request #4 from JaapRood/bug/serialize-meta-data
Browse files Browse the repository at this point in the history
Fix bug where not all meta data is omitted during serialisation
  • Loading branch information
Jaap van Hardeveld authored Feb 1, 2017
2 parents 497df3d + 98dd33f commit 4b0b9d5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
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

0 comments on commit 4b0b9d5

Please sign in to comment.