@@ -611,11 +611,12 @@ describe('app', function() {
611611 } ) ;
612612
613613 describe ( 'app.model(Model)' , function ( ) {
614- var app , db ;
614+ var app , db , MyTestModel ;
615615 beforeEach ( function ( ) {
616616 app = loopback ( ) ;
617617 app . set ( 'remoting' , { errorHandler : { debug : true , log : false } } ) ;
618618 db = loopback . createDataSource ( { connector : loopback . Memory } ) ;
619+ MyTestModel = app . registry . createModel ( 'MyTestModel' ) ;
619620 } ) ;
620621
621622 it ( 'Expose a `Model` to remote clients' , function ( ) {
@@ -626,7 +627,7 @@ describe('app', function() {
626627 expect ( app . models ( ) ) . to . eql ( [ Color ] ) ;
627628 } ) ;
628629
629- it ( 'uses singlar name as app.remoteObjects() key' , function ( ) {
630+ it ( 'uses singular name as app.remoteObjects() key' , function ( ) {
630631 var Color = PersistedModel . extend ( 'color' , { name : String } ) ;
631632 app . model ( Color ) ;
632633 Color . attachTo ( db ) ;
@@ -689,76 +690,26 @@ describe('app', function() {
689690 } ) ;
690691 } ) ;
691692
692- it ( 'accepts null dataSource' , function ( ) {
693- app . model ( 'MyTestModel' , { dataSource : null } ) ;
694- } ) ;
695-
696- it ( 'accepts false dataSource' , function ( ) {
697- app . model ( 'MyTestModel' , { dataSource : false } ) ;
693+ it ( 'accepts null dataSource' , function ( done ) {
694+ app . model ( MyTestModel , { dataSource : null } ) ;
695+ expect ( MyTestModel . dataSource ) . to . eql ( null ) ;
696+ done ( ) ;
698697 } ) ;
699698
700- it ( 'should not require dataSource' , function ( ) {
701- app . model ( 'MyTestModel' , { } ) ;
702- } ) ;
703- } ) ;
704-
705- describe ( 'app.model(name, config)' , function ( ) {
706- var app ;
707-
708- beforeEach ( function ( ) {
709- app = loopback ( ) ;
710- app . dataSource ( 'db' , {
711- connector : 'memory' ,
712- } ) ;
699+ it ( 'accepts false dataSource' , function ( done ) {
700+ app . model ( MyTestModel , { dataSource : false } ) ;
701+ expect ( MyTestModel . getDataSource ( ) ) . to . eql ( null ) ;
702+ done ( ) ;
713703 } ) ;
714704
715- it ( 'Sugar for defining a fully built model' , function ( ) {
716- app . model ( 'foo' , {
717- dataSource : 'db' ,
718- } ) ;
719-
720- var Foo = app . models . foo ;
721- var f = new Foo ( ) ;
722-
723- assert ( f instanceof app . registry . getModel ( 'Model' ) ) ;
705+ it ( 'does not require dataSource' , function ( done ) {
706+ app . model ( MyTestModel ) ;
707+ done ( ) ;
724708 } ) ;
725709
726- it ( 'interprets extra first-level keys as options' , function ( ) {
727- app . model ( 'foo' , {
728- dataSource : 'db' ,
729- base : 'User' ,
730- } ) ;
731-
732- expect ( app . models . foo . definition . settings . base ) . to . equal ( 'User' ) ;
733- } ) ;
734-
735- it ( 'prefers config.options.key over config.key' , function ( ) {
736- app . model ( 'foo' , {
737- dataSource : 'db' ,
738- base : 'User' ,
739- options : {
740- base : 'Application' ,
741- } ,
742- } ) ;
743-
744- expect ( app . models . foo . definition . settings . base ) . to . equal ( 'Application' ) ;
745- } ) ;
746-
747- it ( 'honors config.public options' , function ( ) {
748- app . model ( 'foo' , {
749- dataSource : 'db' ,
750- public : false ,
751- } ) ;
752- expect ( app . models . foo . app ) . to . equal ( app ) ;
753- expect ( app . models . foo . shared ) . to . equal ( false ) ;
754- } ) ;
755-
756- it ( 'defaults config.public to be true' , function ( ) {
757- app . model ( 'foo' , {
758- dataSource : 'db' ,
759- } ) ;
760- expect ( app . models . foo . app ) . to . equal ( app ) ;
761- expect ( app . models . foo . shared ) . to . equal ( true ) ;
710+ it ( 'throws error if model typeof string is passed' , function ( ) {
711+ var fn = function ( ) { app . model ( 'MyTestModel' ) ; } ;
712+ expect ( fn ) . to . throw ( / a p p ( \. m o d e l | \. r e g i s t r y ) / ) ;
762713 } ) ;
763714 } ) ;
764715
@@ -772,15 +723,17 @@ describe('app', function() {
772723 }
773724
774725 assert ( ! previousModel || ! previousModel . dataSource ) ;
775- app . model ( 'TestModel' , { dataSource : 'db' } ) ;
726+ var TestModel = app . registry . createModel ( 'TestModel' ) ;
727+ app . model ( TestModel , { dataSource : 'db' } ) ;
776728 expect ( app . models . TestModel . dataSource ) . to . equal ( app . dataSources . db ) ;
777729 } ) ;
778730 } ) ;
779731
780732 describe ( 'app.models' , function ( ) {
781733 it ( 'is unique per app instance' , function ( ) {
782734 app . dataSource ( 'db' , { connector : 'memory' } ) ;
783- var Color = app . model ( 'Color' , { dataSource : 'db' } ) ;
735+ var Color = app . registry . createModel ( 'Color' ) ;
736+ app . model ( Color , { dataSource : 'db' } ) ;
784737 expect ( app . models . Color ) . to . equal ( Color ) ;
785738 var anotherApp = loopback ( ) ;
786739 expect ( anotherApp . models . Color ) . to . equal ( undefined ) ;
0 commit comments