Skip to content

Commit c54f44e

Browse files
committed
rate_limiter: Simplify new_user() test helper fn
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 fd9d5b5 commit c54f44e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/rate_limiter.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct Bucket {
181181
#[cfg(test)]
182182
mod tests {
183183
use super::*;
184-
use crate::email::Emails;
184+
use crate::schema::users;
185185
use crate::test_util::*;
186186

187187
#[test]
@@ -647,13 +647,17 @@ mod tests {
647647

648648
fn new_user(conn: &mut impl Conn, gh_login: &str) -> QueryResult<i32> {
649649
use crate::models::NewUser;
650+
use diesel::RunQueryDsl;
650651

651652
let user = NewUser {
652653
gh_login,
653654
..NewUser::default()
654-
}
655-
.create_or_update(None, &Emails::new_in_memory(), conn)?;
656-
Ok(user.id)
655+
};
656+
657+
diesel::insert_into(users::table)
658+
.values(user)
659+
.returning(users::id)
660+
.get_result(conn)
657661
}
658662

659663
fn new_user_bucket(

0 commit comments

Comments
 (0)