Skip to content

Commit 48622d5

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 48622d5

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/tests/routes/users/read.rs

Lines changed: 14 additions & 8 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 {
@@ -32,22 +34,26 @@ async fn show_latest_user_case_insensitively() {
3234
// should be used for uniquely identifying GitHub accounts whenever possible. For the
3335
// crates.io/user/:username pages, the best we can do is show the last crates.io account
3436
// created with that username.
35-
assert_ok!(NewUser::new(
37+
38+
let user1 = NewUser::new(
3639
1,
3740
"foobar",
3841
Some("I was first then deleted my github account"),
3942
None,
40-
"bar"
41-
)
42-
.create_or_update(None, &app.as_inner().emails, &mut conn));
43-
assert_ok!(NewUser::new(
43+
"bar",
44+
);
45+
46+
let user2 = NewUser::new(
4447
2,
4548
"FOOBAR",
4649
Some("I was second, I took the foobar username on github"),
4750
None,
48-
"bar"
49-
)
50-
.create_or_update(None, &app.as_inner().emails, &mut conn));
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)