Skip to content

Commit 63ed030

Browse files
committed
models/email: Extract NewEmail::insert() fn
1 parent 4d20df8 commit 63ed030

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/models/email.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ pub struct NewEmail<'a> {
2727
}
2828

2929
impl NewEmail<'_> {
30+
pub async fn insert(&self, conn: &mut AsyncPgConnection) -> QueryResult<()> {
31+
diesel::insert_into(emails::table)
32+
.values(self)
33+
.execute(conn)
34+
.await?;
35+
36+
Ok(())
37+
}
38+
3039
/// Inserts the email into the database and returns the confirmation token,
3140
/// or does nothing if it already exists and returns `None`.
3241
pub async fn insert_if_missing(

src/tests/util/test_app.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ impl TestApp {
120120
///
121121
/// This method updates the database directly
122122
pub async fn db_new_user(&self, username: &str) -> MockCookieUser {
123-
use crate::schema::emails;
124123
use diesel_async::RunQueryDsl;
125124

126125
let mut conn = self.db_conn().await;
@@ -139,11 +138,7 @@ impl TestApp {
139138
verified: true,
140139
};
141140

142-
diesel::insert_into(emails::table)
143-
.values(new_email)
144-
.execute(&mut conn)
145-
.await
146-
.unwrap();
141+
new_email.insert(&mut conn).await.unwrap();
147142

148143
MockCookieUser {
149144
app: self.clone(),

0 commit comments

Comments
 (0)