Skip to content

Commit 904f3d3

Browse files
committed
tests/routes/users/read: Simplify NewUser creation
There is no need for an "upsert" operation here since we know that the database is in a clean state in our tests. Additionally, this drops the need for the `Emails` implementation, since all we want is a user in the database, but without any email address confirmation emails being sent out.
1 parent d16c4c1 commit 904f3d3

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

src/tests/routes/users/read.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::models::NewUser;
2+
use crate::schema::users;
23
use crate::tests::util::{RequestHelper, TestApp};
34
use crate::views::EncodablePublicUser;
5+
use diesel::RunQueryDsl;
46

57
#[derive(Deserialize)]
68
pub 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

Comments
 (0)