1
0
Fork 0

[DEV-2506] StagingBucket: Add ability to prevent bypass

This is a kluge until time can be spent better factoring this
system (using Traits).

* src/bucket/StagingBucket.js (_noStagingBypass): Add field.
  (forbidBypass): Add method to set field.
  (setCommittedValues): Use field.
master
Mike Gerwitz 2017-08-11 11:55:14 -04:00
parent 12d3b5b8d0
commit 5078c7d8d9
2 changed files with 68 additions and 0 deletions

View File

@ -80,6 +80,12 @@ module.exports = Class( 'StagingBucket' )
*/
'private _dirty': false,
/**
* Prevent setCommittedValues from bypassing staging
* @type {boolean}
*/
'private _noStagingBypass': false,
/**
* Initializes staging bucket with the provided data bucket
@ -155,6 +161,11 @@ module.exports = Class( 'StagingBucket' )
*/
'public setCommittedValues': function( data /*, ...*/ )
{
if ( this._noStagingBypass )
{
return this.setValues.apply( this, arguments );
}
this._bucket.setValues.apply( this._bucket, arguments );
// no use in triggering a pre-update, since these values are
@ -165,6 +176,20 @@ module.exports = Class( 'StagingBucket' )
},
/**
* Prevent #setCommittedValues from bypassing staging
*
* When set, #setCommittedValues will act as an alias of #setValues.
*
* @return {StagingBucket} self
*/
'public forbidBypass'()
{
this._noStagingBypass = true;
return this;
},
/**
* Determine whether values have changed
*

View File

@ -26,6 +26,7 @@
const { Class } = require( 'easejs' );
const root = require( '../../' );
const expect = require( 'chai' ).expect;
const sinon = require( 'sinon' );
const {
Bucket,
@ -161,6 +162,48 @@ describe( 'StagingBucket', () =>
} );
} );
} );
describe( "#setCommittedValues", () =>
{
it( "bypasses staging bucket without no bypass flag", () =>
{
const b = createStubBucket();
const bmock = sinon.mock( b );
const data = { foo: [ "bar" ] };
const sut = Sut( b );
bmock.expects( 'setValues' )
.once()
.withExactArgs( data );
sut.setCommittedValues( data );
// no diff if bypassed
expect( sut.getDiff() ).to.deep.equal( {} );
bmock.verify();
} );
it( "does not bypasses staging bucket with no bypass flag", () =>
{
const b = createStubBucket();
const bmock = sinon.mock( b );
const data = { foo: [ "bar" ] };
const sut = Sut( b );
bmock.expects( 'setValues' ).never();
sut.forbidBypass();
sut.setCommittedValues( data );
// should have been staged
expect( sut.getDiff() ).to.deep.equal( data );
bmock.verify();
} );
} );
} );