@@ -17,61 +17,116 @@ describe('Instructor model ', function(){
1717 model = new Model ( ) ;
1818 } ) ;
1919
20- xit ( 'initializes with custom logic' , function ( ) {
20+ it ( 'has the expected routes' , function ( ) {
21+ expect ( model . urlRoot ) . toEqual ( '/api/instructors' ) ;
2122 } ) ;
2223 } ) ;
2324
24- describe ( 'when updating the model for instructor ' , function ( ) {
25+ describe ( 'when updating the model for instructor with errorSpy ' , function ( ) {
2526 var errorSpy ;
2627
2728 beforeEach ( function ( ) {
2829 errorSpy = jasmine . createSpy ( 'Invalid' ) ;
2930 model = new Model ( {
30- id : 1
31+ id : 1 ,
32+ firstName : 'Jeff' ,
33+ lastName : 'Thomas' ,
34+ skills : 'C++, Java'
3135 } ) ;
3236 model . on ( 'invalid' , errorSpy ) ;
33- model . save ( ) ;
3437 } ) ;
3538
3639 it ( 'does not save when firstName is empty ' , function ( ) {
40+ model . set ( 'firstName' , null ) ;
41+ model . save ( ) ;
3742 expect ( errorSpy ) . toHaveBeenCalled ( ) ;
38- expect ( errorSpy ) . toHaveBeenCalledWith (
39- model ,
40- 'firstName cannot be empty' ,
41- { validate : true , validationError : 'firstName cannot be empty' }
42- ) ;
43+ expect ( errorSpy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( model ) ;
44+ expect ( errorSpy . calls . mostRecent ( ) . args [ 1 ] [ 0 ] ) . toEqual (
45+ 'firstName cannot be empty' ) ;
4346 } ) ;
4447
45- // Use if you have transformation logic on set
46- xit ( 'sets the values correctly ' , function ( ) {
47-
48+ it ( 'does not save when lastName is empty ' , function ( ) {
49+ model . set ( 'lastName' , null ) ;
50+ model . save ( ) ;
51+ expect ( errorSpy ) . toHaveBeenCalled ( ) ;
52+ expect ( errorSpy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( model ) ;
53+ expect ( errorSpy . calls . mostRecent ( ) . args [ 1 ] [ 0 ] ) . toEqual (
54+ 'lastName cannot be empty' ) ;
4855 } ) ;
4956
50- // Use if you have transformation logic on get
51- xit ( 'retrieves the correct values ' , function ( ) {
52-
57+ it ( 'does not save when skills is empty ' , function ( ) {
58+ model . set ( 'skills' , null ) ;
59+ model . save ( ) ;
60+ expect ( errorSpy ) . toHaveBeenCalled ( ) ;
61+ expect ( errorSpy . calls . mostRecent ( ) . args [ 0 ] ) . toBe ( model ) ;
62+ expect ( errorSpy . calls . mostRecent ( ) . args [ 1 ] [ 0 ] ) . toEqual (
63+ 'skills cannot be empty' ) ;
5364 } ) ;
5465 } ) ;
5566
56- describe ( 'when changing the state of the model ' , function ( ) {
57- var eventSpy ;
67+ describe ( 'when changing the state of the model without errorSpy' , function ( ) {
5868
5969 beforeEach ( function ( ) {
60- eventSpy = jasmine . createSpy ( 'Change Event' ) ;
70+
6171 model = new Model ( {
6272 id : 1 ,
6373 firstName : 'Mike' ,
64- lastName : 'Foster'
74+ lastName : 'Foster' ,
75+ skills : 'reading'
6576 } ) ;
66- model . on ( 'foo' , eventSpy ) ;
67- model . set ( { firstName : 'changed' , lastName : 'changed' } ) ;
77+
78+ } ) ;
79+
80+ it ( 'does not save when firstName is empty ' , function ( ) {
81+ model . set ( 'firstName' , null ) ;
82+ model . save ( ) ;
83+ expect ( model . validationError ) . toEqual ( [ 'firstName cannot be empty' ] ) ;
6884 } ) ;
6985
70- it ( 'triggers the custom event foo' , function ( ) {
71- expect ( eventSpy ) . toHaveBeenCalled ( ) ;
72- expect ( eventSpy ) . toHaveBeenCalledWith (
73- 'bar'
74- ) ;
86+ it ( 'does not save when firstName and lastName are empty ' , function ( ) {
87+ model . set ( 'firstName' , null ) ;
88+ model . set ( 'lastName' , null ) ;
89+ model . save ( ) ;
90+ expect ( model . validationError ) . toEqual ( [ 'firstName cannot be empty' ,
91+ 'lastName cannot be empty' ] ) ;
92+ } ) ;
93+
94+ it ( 'does not save when firstName and skills are empty ' , function ( ) {
95+ model . set ( 'firstName' , null ) ;
96+ model . set ( 'skills' , null ) ;
97+ model . save ( ) ;
98+ expect ( model . validationError ) . toEqual ( [ 'firstName cannot be empty' ,
99+ 'skills cannot be empty' ] ) ;
100+ } ) ;
101+
102+ it ( 'does not save when lastName is empty ' , function ( ) {
103+ model . set ( 'lastName' , null ) ;
104+ model . save ( ) ;
105+ expect ( model . validationError ) . toEqual ( [ 'lastName cannot be empty' ] ) ;
106+ } ) ;
107+
108+ it ( 'does not save when lastName and skills are empty ' , function ( ) {
109+ model . set ( 'lastName' , null ) ;
110+ model . set ( 'skills' , null ) ;
111+ model . save ( ) ;
112+ expect ( model . validationError ) . toEqual ( [ 'lastName cannot be empty' ,
113+ 'skills cannot be empty' ] ) ;
114+ } ) ;
115+
116+ it ( 'does not save when skills is empty ' , function ( ) {
117+ model . set ( 'skills' , null ) ;
118+ model . save ( ) ;
119+ expect ( model . validationError ) . toEqual ( [ 'skills cannot be empty' ] ) ;
120+ } ) ;
121+
122+ it ( 'does not save when all fields are empty ' , function ( ) {
123+ model . set ( 'firstName' , null ) ;
124+ model . set ( 'lastName' , null ) ;
125+ model . set ( 'skills' , null ) ;
126+ model . save ( ) ;
127+ expect ( model . validationError ) . toEqual ( [ 'firstName cannot be empty' ,
128+ 'lastName cannot be empty' ,
129+ 'skills cannot be empty' ] ) ;
75130 } ) ;
76131 } ) ;
77132} ) ;
0 commit comments