1
1
var Backend = require ( '../../lib/backend' ) ;
2
2
var expect = require ( 'expect.js' ) ;
3
3
4
- describe ( 'client query subscribe ' , function ( ) {
4
+ describe ( 'client doc ' , function ( ) {
5
5
6
6
beforeEach ( function ( ) {
7
7
this . backend = new Backend ( ) ;
@@ -25,6 +25,39 @@ describe('client query subscribe', function() {
25
25
expect ( doc ) . not . equal ( doc2 ) ;
26
26
} ) ;
27
27
28
+ it ( 'calling doc.destroy on subscribed doc unregisters it (no callback)' , function ( ) {
29
+ var connection = this . connection ;
30
+ var doc = connection . get ( 'dogs' , 'fido' ) ;
31
+ expect ( connection . getExisting ( 'dogs' , 'fido' ) ) . equal ( doc ) ;
32
+
33
+ doc . subscribe ( function ( err ) {
34
+ if ( err ) return done ( err ) ;
35
+ doc . destroy ( ) ;
36
+ doc . whenNothingPending ( function ( ) {
37
+ expect ( connection . getExisting ( 'dogs' , 'fido' ) ) . equal ( undefined ) ;
38
+
39
+ var doc2 = connection . get ( 'dogs' , 'fido' ) ;
40
+ expect ( doc ) . not . equal ( doc2 ) ;
41
+ } ) ;
42
+ } ) ;
43
+ } ) ;
44
+
45
+ it ( 'calling doc.destroy on subscribed doc unregisters it (with callback)' , function ( ) {
46
+ var connection = this . connection ;
47
+ var doc = connection . get ( 'dogs' , 'fido' ) ;
48
+ expect ( connection . getExisting ( 'dogs' , 'fido' ) ) . equal ( doc ) ;
49
+
50
+ doc . subscribe ( function ( err ) {
51
+ if ( err ) return done ( err ) ;
52
+ doc . destroy ( function ( ) {
53
+ expect ( connection . getExisting ( 'dogs' , 'fido' ) ) . equal ( undefined ) ;
54
+
55
+ var doc2 = connection . get ( 'dogs' , 'fido' ) ;
56
+ expect ( doc ) . not . equal ( doc2 ) ;
57
+ } ) ;
58
+ } ) ;
59
+ } ) ;
60
+
28
61
it ( 'getting then destroying then getting returns a new doc object' , function ( ) {
29
62
var doc = this . connection . get ( 'dogs' , 'fido' ) ;
30
63
doc . destroy ( ) ;
0 commit comments