@ -16,20 +16,6 @@
( function ( ) {
( function ( ) {
'use strict' ;
'use strict' ;
function clear ( done ) {
var convos = new Whisper . ConversationCollection ( ) ;
return convos . fetch ( ) . then ( function ( ) {
convos . destroyAll ( ) . then ( function ( ) {
var messages = new Whisper . MessageCollection ( ) ;
return messages . fetch ( ) . then ( function ( ) {
messages . destroyAll ( ) . then ( function ( ) {
done ( ) ;
} ) ;
} ) ;
} ) ;
} ) ;
}
var attributes = { type : 'outgoing' ,
var attributes = { type : 'outgoing' ,
body : 'hi' ,
body : 'hi' ,
conversationId : 'foo' ,
conversationId : 'foo' ,
@ -37,8 +23,8 @@
timestamp : new Date ( ) . getTime ( ) } ;
timestamp : new Date ( ) . getTime ( ) } ;
describe ( 'ConversationCollection' , function ( ) {
describe ( 'ConversationCollection' , function ( ) {
before ( clear ) ;
before ( clear Database ) ;
after ( clear ) ;
after ( clear Database ) ;
it ( 'adds without saving' , function ( ) {
it ( 'adds without saving' , function ( ) {
var convos = new Whisper . ConversationCollection ( ) ;
var convos = new Whisper . ConversationCollection ( ) ;
@ -107,7 +93,7 @@
message . save ( ) . then ( done )
message . save ( ) . then ( done )
} ) ;
} ) ;
} ) ;
} ) ;
after ( clear ) ;
after ( clear Database ) ;
it ( 'contains its own messages' , function ( done ) {
it ( 'contains its own messages' , function ( done ) {
var convo = new Whisper . ConversationCollection ( ) . add ( { id : 'foobar' } ) ;
var convo = new Whisper . ConversationCollection ( ) . add ( { id : 'foobar' } ) ;
@ -124,26 +110,6 @@
done ( ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
} ) ;
it ( 'has most recent messages first' , function ( done ) {
var convo = new Whisper . ConversationCollection ( ) . add ( { id : 'barfoo' } ) ;
convo . messages ( ) . add ( {
body : 'first message' ,
conversationId : convo . id ,
timestamp : new Date ( ) . getTime ( ) - 5000
} ) . save ( ) . then ( function ( ) {
convo . messages ( ) . add ( {
body : 'second message' ,
conversationId : convo . id
} ) . save ( ) . then ( function ( ) {
convo . fetch ( ) . then ( function ( ) {
assert . strictEqual ( convo . messages ( ) . at ( 0 ) . get ( 'body' ) , 'second message' ) ;
assert . strictEqual ( convo . messages ( ) . at ( 1 ) . get ( 'body' ) , 'first message' ) ;
done ( ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ( ) ; ;
} ) ( ) ; ;