File tree Expand file tree Collapse file tree 5 files changed +36
-36
lines changed Expand file tree Collapse file tree 5 files changed +36
-36
lines changed Original file line number Diff line number Diff line change
1
+ use bon:: Builder ;
1
2
use chrono:: NaiveDateTime ;
2
3
use diesel:: prelude:: * ;
3
4
use diesel_async:: scoped_futures:: ScopedFutureExt ;
@@ -106,7 +107,7 @@ impl User {
106
107
}
107
108
108
109
/// Represents a new user record insertable to the `users` table
109
- #[ derive( Insertable , Debug , Default ) ]
110
+ #[ derive( Insertable , Debug , Builder ) ]
110
111
#[ diesel( table_name = users, check_for_backend( diesel:: pg:: Pg ) ) ]
111
112
pub struct NewUser < ' a > {
112
113
pub gh_id : i32 ,
@@ -124,13 +125,13 @@ impl<'a> NewUser<'a> {
124
125
gh_avatar : Option < & ' a str > ,
125
126
gh_access_token : & ' a str ,
126
127
) -> Self {
127
- NewUser {
128
- gh_id,
129
- gh_login,
130
- name,
131
- gh_avatar,
132
- gh_access_token,
133
- }
128
+ NewUser :: builder ( )
129
+ . gh_id ( gh_id )
130
+ . gh_login ( gh_login )
131
+ . maybe_name ( name)
132
+ . maybe_gh_avatar ( gh_avatar)
133
+ . gh_access_token ( gh_access_token )
134
+ . build ( )
134
135
}
135
136
136
137
/// Inserts the user into the database, or updates an existing one.
Original file line number Diff line number Diff line change @@ -702,10 +702,11 @@ mod tests {
702
702
async fn new_user ( conn : & mut AsyncPgConnection , gh_login : & str ) -> QueryResult < i32 > {
703
703
use crate :: models:: NewUser ;
704
704
705
- let user = NewUser {
706
- gh_login,
707
- ..NewUser :: default ( )
708
- } ;
705
+ let user = NewUser :: builder ( )
706
+ . gh_id ( 0 )
707
+ . gh_login ( gh_login)
708
+ . gh_access_token ( "some random token" )
709
+ . build ( ) ;
709
710
710
711
diesel:: insert_into ( users:: table)
711
712
. values ( user)
Original file line number Diff line number Diff line change @@ -93,13 +93,11 @@ pub struct OwnerResp {
93
93
}
94
94
95
95
fn new_user ( login : & str ) -> NewUser < ' _ > {
96
- NewUser {
97
- gh_id : next_gh_id ( ) ,
98
- gh_login : login,
99
- name : None ,
100
- gh_avatar : None ,
101
- gh_access_token : "some random token" ,
102
- }
96
+ NewUser :: builder ( )
97
+ . gh_id ( next_gh_id ( ) )
98
+ . gh_login ( login)
99
+ . gh_access_token ( "some random token" )
100
+ . build ( )
103
101
}
104
102
105
103
fn new_team ( login : & str ) -> NewTeam < ' _ > {
Original file line number Diff line number Diff line change @@ -770,13 +770,11 @@ async fn inactive_users_dont_get_invitations() {
770
770
let invited_gh_login = "user_bar" ;
771
771
let krate_name = "inactive_test" ;
772
772
773
- let user = NewUser {
774
- gh_id : -1 ,
775
- gh_login : invited_gh_login,
776
- name : None ,
777
- gh_avatar : None ,
778
- gh_access_token : "some random token" ,
779
- } ;
773
+ let user = NewUser :: builder ( )
774
+ . gh_id ( -1 )
775
+ . gh_login ( invited_gh_login)
776
+ . gh_access_token ( "some random token" )
777
+ . build ( ) ;
780
778
781
779
diesel:: insert_into ( users:: table)
782
780
. values ( user)
Original file line number Diff line number Diff line change @@ -76,12 +76,13 @@ async fn github_without_email_does_not_overwrite_email() -> anyhow::Result<()> {
76
76
. await ;
77
77
78
78
// Simulate the same user logging in via GitHub again, still with no email in GitHub.
79
- let u = NewUser {
79
+ let u = NewUser :: builder ( )
80
80
// Use the same github ID to link to the existing account
81
- gh_id : user_without_github_email_model. gh_id ,
82
- // new_user uses a None email; the rest of the fields are arbitrary
83
- ..new_user ( "arbitrary_username" )
84
- } ;
81
+ . gh_id ( user_without_github_email_model. gh_id )
82
+ . gh_login ( "arbitrary_username" )
83
+ . gh_access_token ( "some random token" )
84
+ . build ( ) ;
85
+
85
86
let u = u
86
87
. create_or_update ( None , & app. as_inner ( ) . emails , & mut conn)
87
88
. await ?;
@@ -115,12 +116,13 @@ async fn github_with_email_does_not_overwrite_email() -> anyhow::Result<()> {
115
116
116
117
let emails = app. as_inner ( ) . emails . clone ( ) ;
117
118
118
- let u = NewUser {
119
+ let u = NewUser :: builder ( )
119
120
// Use the same github ID to link to the existing account
120
- gh_id : model. gh_id ,
121
- // the rest of the fields are arbitrary
122
- ..new_user ( "arbitrary_username" )
123
- } ;
121
+ . gh_id ( model. gh_id )
122
+ . gh_login ( "arbitrary_username" )
123
+ . gh_access_token ( "some random token" )
124
+ . build ( ) ;
125
+
124
126
let u = u
125
127
. create_or_update ( Some ( new_github_email) , & emails, & mut conn)
126
128
. await ?;
You can’t perform that action at this time.
0 commit comments