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