Skip to content

Commit

Permalink
Merge pull request #38 from hoxton-one/bug/list-whenready-returns-record
Browse files Browse the repository at this point in the history
list uses correct arguments for whenReady
  • Loading branch information
WolframHempel committed Dec 14, 2015
2 parents 0629c37 + a67498e commit e790414
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/record/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var List = function( recordHandler, name, options ) {

this.delete = this._record.delete.bind( this._record );
this.discard = this._record.discard.bind( this._record );
this.whenReady = this._record.whenReady.bind( this._record );
this.whenReady = this._record.whenReady.bind( this );
};

EventEmitter( List.prototype );
Expand Down
4 changes: 4 additions & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ exports.deepEquals = function( objA, objB ) {
};

exports.shallowCopy = function( obj ) {
if( obj === null ) {
return null;
}

if( typeof obj !== OBJECT ) {
return obj;
}
Expand Down
11 changes: 11 additions & 0 deletions test-e2e/specs/recordSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ describe( 'record', function() {
done();
}, 20 );
});

it( 'sets a path with null', function( done ) {
clientB.record.getRecord( 'record1' ).set( 'city', null );
expect( clientB.record.getRecord( 'record1' ).get( 'city' ) ).toBeNull();
expect( clientA.record.getRecord( 'record1' ).get( 'city' ) ).toBe( 'London' );

setTimeout(function(){
expect( clientA.record.getRecord( 'record1' ).get( 'city' ) ).toBeNull();
done();
}, 20 );
});

it( 'subscribes and unsubscribes', function( done ) {
var pet,
Expand Down
3 changes: 2 additions & 1 deletion test-unit/unit/record/list-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe( 'lists contain arrays of record names', function(){
it( 'creates the list', function(){
list = new List( recordHandler, 'someList', {} );
list.subscribe( changeCallback );
list.on( 'ready', readyCallback );
list.whenReady( readyCallback );
expect( list.subscribe.bind( list, 'somePath', changeCallback ) ).toThrow();
expect( list.getEntries ).toBeDefined();
expect( recordHandler._connection.lastSendMessage ).toBe( msg( 'R|CR|someList+' ) );
Expand All @@ -36,6 +36,7 @@ describe( 'lists contain arrays of record names', function(){
expect( list.getEntries() ).toEqual(['entryA', 'entryB' ]);
expect( changeCallback ).toHaveBeenCalledWith(['entryA', 'entryB' ]);
expect( readyCallback ).toHaveBeenCalled();
expect( readyCallback ).toHaveBeenCalledWith( list );
expect( list.isEmpty() ).toBe( false );
});

Expand Down
13 changes: 13 additions & 0 deletions test-unit/unit/utils/utilsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,17 @@ describe( 'shallow copy', function(){
expect( copy ).toEqual( original );
expect( copy ).not.toBe( original );
});

it( 'copies objects with null values', function(){
var original = { firstname: 'Wolfram', lastname: null },
copy = utils.shallowCopy( original );

expect( copy ).toEqual( original );
expect( copy ).not.toBe( original );
});

it( 'copies null values', function(){
var copy = utils.shallowCopy( null );
expect( copy ).toBeNull();
});
});

0 comments on commit e790414

Please sign in to comment.