11use crate :: models:: NewUser ;
2+ use crate :: schema:: users;
23use crate :: tests:: util:: { RequestHelper , TestApp } ;
34use crate :: views:: EncodablePublicUser ;
5+ use diesel:: RunQueryDsl ;
46
57#[ derive( Deserialize ) ]
68pub struct UserShowPublicResponse {
@@ -25,29 +27,33 @@ async fn show_latest_user_case_insensitively() {
2527 let ( app, anon) = TestApp :: init ( ) . empty ( ) ;
2628 let mut conn = app. db_conn ( ) ;
2729
28- // Please do not delete or modify the setup of this test in order to get it to pass.
29- // This setup mimics how GitHub works. If someone abandons a GitHub account, the username is
30- // available for anyone to take. We need to support having multiple user accounts
31- // with the same gh_login in crates.io. `gh_id` is stable across renames, so that field
32- // should be used for uniquely identifying GitHub accounts whenever possible. For the
33- // crates.io/user/:username pages, the best we can do is show the last crates.io account
34- // created with that username.
35- assert_ok ! ( NewUser :: new(
36- 1 ,
37- "foobar" ,
38- Some ( "I was first then deleted my github account" ) ,
39- None ,
40- "bar"
41- )
42- . create_or_update( None , & app. as_inner( ) . emails, & mut conn) ) ;
43- assert_ok ! ( NewUser :: new(
44- 2 ,
45- "FOOBAR" ,
46- Some ( "I was second, I took the foobar username on github" ) ,
47- None ,
48- "bar"
49- )
50- . create_or_update( None , & app. as_inner( ) . emails, & mut conn) ) ;
30+ // Please do not delete or modify the setup of this test in order to get it to pass.
31+ // This setup mimics how GitHub works. If someone abandons a GitHub account, the username is
32+ // available for anyone to take. We need to support having multiple user accounts
33+ // with the same gh_login in crates.io. `gh_id` is stable across renames, so that field
34+ // should be used for uniquely identifying GitHub accounts whenever possible. For the
35+ // crates.io/user/:username pages, the best we can do is show the last crates.io account
36+ // created with that username.
37+
38+ let user1 = NewUser :: new (
39+ 1 ,
40+ "foobar" ,
41+ Some ( "I was first then deleted my github account" ) ,
42+ None ,
43+ "bar" ,
44+ ) ;
45+
46+ let user2 = NewUser :: new (
47+ 2 ,
48+ "FOOBAR" ,
49+ Some ( "I was second, I took the foobar username on github" ) ,
50+ None ,
51+ "bar" ,
52+ ) ;
53+
54+ assert_ok ! ( diesel:: insert_into( users:: table)
55+ . values( & vec![ user1, user2] )
56+ . execute( & mut conn) ) ;
5157
5258 let json: UserShowPublicResponse = anon. get ( "/api/v1/users/fOObAr" ) . await . good ( ) ;
5359 assert_eq ! (
0 commit comments