Skip to content

Commit 8293148

Browse files
committed
typosquat/test_util: Simplify user() fn
If `create_or_update()` is called with a `None` argument then no emails will be saved and sent, which means that the `Emails` instance isn't actually being used and created for nothing. Additionally, we don't need the "upsert" behavior since our test database shouldn't start with any content anyway. In other words: we can just `INSERT` the `NewUser` instance directly and remove the `email` field from the `Faker` struct.
1 parent ed4eb9f commit 8293148

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/typosquat/test_util.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@ use crate::{
55
models::{
66
Crate, CrateOwner, NewCrate, NewTeam, NewUser, NewVersion, Owner, OwnerKind, User, Version,
77
},
8-
schema::{crate_downloads, crate_owners},
9-
Emails,
8+
schema::{crate_downloads, crate_owners, users},
109
};
1110

12-
pub struct Faker {
13-
emails: Emails,
14-
}
11+
pub struct Faker {}
1512

1613
impl Faker {
1714
pub fn new() -> Self {
18-
Self {
19-
emails: Emails::new_in_memory(),
20-
}
15+
Self {}
2116
}
2217

2318
pub fn add_crate_to_team(
@@ -91,13 +86,11 @@ impl Faker {
9186
))
9287
}
9388

94-
pub fn user(&mut self, conn: &mut PgConnection, login: &str) -> anyhow::Result<User> {
95-
Ok(
96-
NewUser::new(next_gh_id(), login, None, None, "token").create_or_update(
97-
None,
98-
&self.emails,
99-
conn,
100-
)?,
101-
)
89+
pub fn user(&mut self, conn: &mut PgConnection, login: &str) -> QueryResult<User> {
90+
let user = NewUser::new(next_gh_id(), login, None, None, "token");
91+
92+
diesel::insert_into(users::table)
93+
.values(user)
94+
.get_result(conn)
10295
}
10396
}

0 commit comments

Comments
 (0)