From 3b4bb4d4315a43e8a6ddffa0d57c0fd7cb111d2c Mon Sep 17 00:00:00 2001 From: Michael Paulson Date: Sun, 13 Sep 2015 11:46:30 -0700 Subject: [PATCH] found a small bug in how we are adding nulls to error paths when found after a reference. --- lib/get/onValueType.js | 4 ++-- test/get-core/errors.spec.js | 29 ++++++++++++++++++++++++++++- test/get-core/references.spec.js | 21 +++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/lib/get/onValueType.js b/lib/get/onValueType.js index 10ec3694..937a9b60 100644 --- a/lib/get/onValueType.js +++ b/lib/get/onValueType.js @@ -52,7 +52,7 @@ module.exports = function onValueType( // If there is an error, then report it as a value if else if (currType === $error) { if (fromReference) { - requestedPath.push(null); + requestedPath[depth] = null; } if (isJSONG || model._treatErrorsAsValues) { onValue(model, node, seed, depth, outerResults, requestedPath, @@ -65,7 +65,7 @@ module.exports = function onValueType( // Report the value else { if (fromReference) { - requestedPath[depth + 1] = null; + requestedPath[depth] = null; } if (!requiresMaterializedToReport || diff --git a/test/get-core/errors.spec.js b/test/get-core/errors.spec.js index ebd5987d..f81fb685 100644 --- a/test/get-core/errors.spec.js +++ b/test/get-core/errors.spec.js @@ -15,8 +15,13 @@ describe('Errors', function() { reference: ref(['to', 'error']), to: { error: error('Oops!'), - expired: expired + expired: expired, + title: 'Hello World' }, + list: { + 0: ref(['to']), + 1: ref(['to', 'error']) + } }; }; @@ -81,5 +86,27 @@ describe('Errors', function() { cache: errorCache }); }); + + it('should report both values and errors when error is less length than value path.', function() { + getCoreRunner({ + input: [ + ['list', {to: 1}, 'title'] + ], + output: { + json: { + list: { + 0: { + title: 'Hello World' + } + } + } + }, + errors: [{ + path: ['list', 1, null], + value: 'Oops!' + }], + cache: errorCache + }); + }); }); diff --git a/test/get-core/references.spec.js b/test/get-core/references.spec.js index a056bc68..1e831355 100644 --- a/test/get-core/references.spec.js +++ b/test/get-core/references.spec.js @@ -13,6 +13,7 @@ describe('References', function() { circular: ref(['circular', 'next']), to: { reference: ref(['to']), + toValue: ref(['to', 'title']), title: 'Title' }, toShort: 'Short' @@ -57,5 +58,25 @@ describe('References', function() { }); }); + it('should ensure that values are followed correctly when through references and previous paths have longer lengths to litter the requested path.', function() { + getCoreRunner({ + input: [ + ['to', ['reference', 'toValue'], 'title'], + ], + output: { + json: { + to: { + reference: { + title: 'Title' + }, + toValue: 'Title' + } + } + }, + cache: referenceCache + }); + }); + + });