@@ -41,32 +41,147 @@ describe('User Model', function() {
41
41
} ) ;
42
42
43
43
describe ( '#email' , function ( ) {
44
- it ( 'should fail when saving without an email' , function ( ) {
44
+ it ( 'should fail when saving with a blank email' , function ( ) {
45
45
user . email = '' ;
46
46
return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . rejected ;
47
47
} ) ;
48
+
49
+ it ( 'should fail when saving with a null email' , function ( ) {
50
+ user . email = null ;
51
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . rejected ;
52
+ } ) ;
53
+
54
+ it ( 'should fail when saving without an email' , function ( ) {
55
+ user . email = undefined ;
56
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . rejected ;
57
+ } ) ; < % if ( filters . oauth && filters . googleAuth ) { % >
58
+
59
+ context ( 'given user provider is google' , function ( ) {
60
+ beforeEach ( function ( ) {
61
+ user . provider = 'google' ;
62
+ } ) ;
63
+
64
+ it ( 'should succeed when saving without an email' , function ( ) {
65
+ user . email = null ;
66
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . fulfilled ;
67
+ } ) ;
68
+ } ) ; < % } % > < % if ( filters . oauth && filters . facebookAuth ) { % >
69
+
70
+ context ( 'given user provider is facebook' , function ( ) {
71
+ beforeEach ( function ( ) {
72
+ user . provider = 'facebook' ;
73
+ } ) ;
74
+
75
+ it ( 'should succeed when saving without an email' , function ( ) {
76
+ user . email = null ;
77
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . fulfilled ;
78
+ } ) ;
79
+ } ) ; < % } % > < % if ( filters . oauth && filters . twitterAuth ) { % >
80
+
81
+ context ( 'given user provider is twitter' , function ( ) {
82
+ beforeEach ( function ( ) {
83
+ user . provider = 'twitter' ;
84
+ } ) ;
85
+
86
+ it ( 'should succeed when saving without an email' , function ( ) {
87
+ user . email = null ;
88
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . fulfilled ;
89
+ } ) ;
90
+ } ) ; < % } % > < % if ( filters . oauth ) { % >
91
+
92
+ context ( 'given user provider is github' , function ( ) {
93
+ beforeEach ( function ( ) {
94
+ user . provider = 'github' ;
95
+ } ) ;
96
+
97
+ it ( 'should succeed when saving without an email' , function ( ) {
98
+ user . email = null ;
99
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . fulfilled ;
100
+ } ) ;
101
+ } ) ; < % } % >
48
102
} ) ;
49
103
50
104
describe ( '#password' , function ( ) {
51
- beforeEach ( function ( ) {
52
- return user . save ( ) ;
105
+ it ( 'should fail when saving with a blank password' , function ( ) {
106
+ user . password = '' ;
107
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . rejected ;
53
108
} ) ;
54
109
55
- it ( 'should authenticate user if valid' , function ( ) {
56
- < %= expect ( ) % > user . authenticate ( 'password' ) < %= to ( ) % > . be . true ;
110
+ it ( 'should fail when saving with a null password' , function ( ) {
111
+ user . password = null ;
112
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . rejected ;
57
113
} ) ;
58
114
59
- it ( 'should not authenticate user if invalid' , function ( ) {
60
- < %= expect ( ) % > user . authenticate ( 'blah' ) < %= to ( ) % > . not . be . true ;
115
+ it ( 'should fail when saving without a password' , function ( ) {
116
+ user . password = undefined ;
117
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . rejected ;
61
118
} ) ;
62
119
63
- it ( 'should remain the same hash unless the password is updated' , function ( ) {
64
- user . name = 'Test User' ;
65
- return < %= expect ( ) % > user . save ( )
66
- . then ( function ( u ) {
67
- return u . authenticate ( 'password' ) ;
68
- } ) < %= to ( ) % > . eventually . be . true ;
69
- } ) ;
120
+ context ( 'given the user has been previously saved' , function ( ) {
121
+ beforeEach ( function ( ) {
122
+ return user . save ( ) ;
123
+ } ) ;
124
+
125
+ it ( 'should authenticate user if valid' , function ( ) {
126
+ < %= expect ( ) % > user . authenticate ( 'password' ) < %= to ( ) % > . be . true ;
127
+ } ) ;
128
+
129
+ it ( 'should not authenticate user if invalid' , function ( ) {
130
+ < %= expect ( ) % > user . authenticate ( 'blah' ) < %= to ( ) % > . not . be . true ;
131
+ } ) ;
132
+
133
+ it ( 'should remain the same hash unless the password is updated' , function ( ) {
134
+ user . name = 'Test User' ;
135
+ return < %= expect ( ) % > user . save ( )
136
+ . then ( function ( u ) {
137
+ return u . authenticate ( 'password' ) ;
138
+ } ) < %= to ( ) % > . eventually . be . true ;
139
+ } ) ;
140
+ } ) ; < % if ( filters . oauth && filters . googleAuth ) { % >
141
+
142
+ context ( 'given user provider is google' , function ( ) {
143
+ beforeEach ( function ( ) {
144
+ user . provider = 'google' ;
145
+ } ) ;
146
+
147
+ it ( 'should succeed when saving without a password' , function ( ) {
148
+ user . password = null ;
149
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . fulfilled ;
150
+ } ) ;
151
+ } ) ; < % } % > < % if ( filters . oauth && filters . facebookAuth ) { % >
152
+
153
+ context ( 'given user provider is facebook' , function ( ) {
154
+ beforeEach ( function ( ) {
155
+ user . provider = 'facebook' ;
156
+ } ) ;
157
+
158
+ it ( 'should succeed when saving without a password' , function ( ) {
159
+ user . password = null ;
160
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . fulfilled ;
161
+ } ) ;
162
+ } ) ; < % } % > < % if ( filters . oauth && filters . twitterAuth ) { % >
163
+
164
+ context ( 'given user provider is twitter' , function ( ) {
165
+ beforeEach ( function ( ) {
166
+ user . provider = 'twitter' ;
167
+ } ) ;
168
+
169
+ it ( 'should succeed when saving without a password' , function ( ) {
170
+ user . password = null ;
171
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . fulfilled ;
172
+ } ) ;
173
+ } ) ; < % } % > < % if ( filters . oauth ) { % >
174
+
175
+ context ( 'given user provider is github' , function ( ) {
176
+ beforeEach ( function ( ) {
177
+ user . provider = 'github' ;
178
+ } ) ;
179
+
180
+ it ( 'should succeed when saving without a password' , function ( ) {
181
+ user . password = null ;
182
+ return < %= expect ( ) % > user . save ( ) < %= to ( ) % > . be . fulfilled ;
183
+ } ) ;
184
+ } ) ; < % } % >
70
185
} ) ;
71
186
72
187
} ) ;
0 commit comments