@@ -110,7 +110,7 @@ fn me() {
110
110
let user = app. db_new_user ( "foo" ) ;
111
111
let json = user. show_me ( ) ;
112
112
113
- assert_eq ! ( json. user. email , user. as_model( ) . email ) ;
113
+ assert_eq ! ( json. user. name , user. as_model( ) . name ) ;
114
114
}
115
115
116
116
#[ test]
@@ -141,21 +141,19 @@ fn show_latest_user_case_insensitively() {
141
141
t ! ( NewUser :: new(
142
142
1 ,
143
143
"foobar" ,
144
-
145
144
Some ( "I was first then deleted my github account" ) ,
146
145
None ,
147
146
"bar"
148
147
)
149
- . create_or_update( conn) ) ;
148
+ . create_or_update( None , conn) ) ;
150
149
t ! ( NewUser :: new(
151
150
2 ,
152
151
"FOOBAR" ,
153
-
154
152
Some ( "I was second, I took the foobar username on github" ) ,
155
153
None ,
156
154
"bar"
157
155
)
158
- . create_or_update( conn) ) ;
156
+ . create_or_update( None , conn) ) ;
159
157
} ) ;
160
158
161
159
let json: UserShowPublicResponse = anon. get ( "api/v1/users/fOObAr" ) . good ( ) ;
@@ -324,7 +322,7 @@ fn updating_existing_user_doesnt_change_api_token() {
324
322
325
323
let user = app. db ( |conn| {
326
324
// Reuse gh_id but use new gh_login and gh_access_token
327
- t ! ( NewUser :: new( gh_id, "bar" , None , None , None , "bar_token" ) . create_or_update( conn) ) ;
325
+ t ! ( NewUser :: new( gh_id, "bar" , None , None , "bar_token" ) . create_or_update( None , conn) ) ;
328
326
329
327
// Use the original API token to find the now updated user
330
328
t ! ( User :: find_by_api_token( conn, token) )
@@ -353,7 +351,7 @@ fn github_without_email_does_not_overwrite_email() {
353
351
// Don't use app.db_new_user because it adds a verified email.
354
352
let user_without_github_email = app. db ( |conn| {
355
353
let u = new_user ( "arbitrary_username" ) ;
356
- let u = u. create_or_update ( conn) . unwrap ( ) ;
354
+ let u = u. create_or_update ( None , conn) . unwrap ( ) ;
357
355
MockCookieUser :: new ( & app, u)
358
356
} ) ;
359
357
let user_without_github_email_model = user_without_github_email. as_model ( ) ;
@@ -373,7 +371,7 @@ fn github_without_email_does_not_overwrite_email() {
373
371
// new_user uses a None email; the rest of the fields are arbitrary
374
372
..new_user ( "arbitrary_username" )
375
373
} ;
376
- let u = u. create_or_update ( conn) . unwrap ( ) ;
374
+ let u = u. create_or_update ( None , conn) . unwrap ( ) ;
377
375
MockCookieUser :: new ( & app, u)
378
376
} ) ;
379
377
@@ -386,9 +384,16 @@ fn github_without_email_does_not_overwrite_email() {
386
384
*/
387
385
#[ test]
388
386
fn github_with_email_does_not_overwrite_email ( ) {
387
+ use cargo_registry:: schema:: emails;
388
+
389
389
let ( app, _, user) = TestApp :: init ( ) . with_user ( ) ;
390
390
let model = user. as_model ( ) ;
391
- let original_email = & model. email ;
391
+ let original_email = app. db ( |conn| {
392
+ Email :: belonging_to ( model)
393
+ . select ( emails:: email)
394
+ . first :: < String > ( & * conn)
395
+ . unwrap ( )
396
+ } ) ;
392
397
393
398
let new_github_email =
"[email protected] " ;
394
399
@@ -397,16 +402,15 @@ fn github_with_email_does_not_overwrite_email() {
397
402
let u = NewUser {
398
403
// Use the same github ID to link to the existing account
399
404
gh_id : model. gh_id ,
400
- email : Some ( new_github_email) ,
401
405
// the rest of the fields are arbitrary
402
406
..new_user ( "arbitrary_username" )
403
407
} ;
404
- let u = u. create_or_update ( conn) . unwrap ( ) ;
408
+ let u = u. create_or_update ( Some ( new_github_email ) , conn) . unwrap ( ) ;
405
409
MockCookieUser :: new ( & app, u)
406
410
} ) ;
407
411
408
412
let json = user_with_different_email_in_github. show_me ( ) ;
409
- assert_eq ! ( json. user. email, * original_email) ;
413
+ assert_eq ! ( json. user. email, Some ( original_email) ) ;
410
414
}
411
415
412
416
/* Given a crates.io user, check that the user's email can be
@@ -512,10 +516,9 @@ fn test_confirm_user_email() {
512
516
// email directly into the database and we want to test the verification flow here.
513
517
let user = app. db ( |conn| {
514
518
let u = NewUser {
515
-
516
519
..new_user ( "arbitrary_username" )
517
520
} ;
518
- let u = u. create_or_update ( conn) . unwrap ( ) ;
521
+ let u = u. create_or_update ( None , conn) . unwrap ( ) ;
519
522
MockCookieUser :: new ( & app, u)
520
523
} ) ;
521
524
let user_model = user. as_model ( ) ;
@@ -551,10 +554,9 @@ fn test_existing_user_email() {
551
554
// email directly into the database and we want to test the verification flow here.
552
555
let user = app. db ( |conn| {
553
556
let u = NewUser {
554
-
555
557
..new_user ( "arbitrary_username" )
556
558
} ;
557
- let u = u. create_or_update ( conn) . unwrap ( ) ;
559
+ let u = u. create_or_update ( None , conn) . unwrap ( ) ;
558
560
update ( Email :: belonging_to ( & u) )
559
561
// Users created before we added verification will have
560
562
// `NULL` in the `token_generated_at` column.
0 commit comments