diff --git a/src/bin/update-downloads.rs b/src/bin/update-downloads.rs index 89592fb8070..744aa46f963 100644 --- a/src/bin/update-downloads.rs +++ b/src/bin/update-downloads.rs @@ -252,6 +252,14 @@ mod test { assert_eq!(Ok(false), processed); } + fn version_find_first(conn: &PgConnection, id: i32) -> Version { + versions::table + .find(id) + .select(cargo_registry::models::version::ALL_COLUMNS) + .first::(conn) + .unwrap() + } + #[test] fn increment_a_little() { use diesel::dsl::*; @@ -286,21 +294,13 @@ mod test { .execute(&conn) .unwrap(); - let version_before = versions::table - .find(version.id) - .select(cargo_registry::models::version::ALL_COLUMNS) - .first::(&conn) - .unwrap(); + let version_before = version_find_first(&conn, version.id); let krate_before = Crate::all() .filter(crates::id.eq(krate.id)) .first::(&conn) .unwrap(); crate::update(&conn).unwrap(); - let version2 = versions::table - .find(version.id) - .select(cargo_registry::models::version::ALL_COLUMNS) - .first::(&conn) - .unwrap(); + let version2 = version_find_first(&conn, version.id); assert_eq!(version2.downloads, 2); assert_eq!(version2.updated_at, version_before.updated_at); let krate2 = Crate::all() @@ -311,11 +311,7 @@ mod test { assert_eq!(krate2.updated_at, krate_before.updated_at); crate_downloads!(&conn, krate.id, 1); crate::update(&conn).unwrap(); - let version3 = versions::table - .find(version.id) - .select(cargo_registry::models::version::ALL_COLUMNS) - .first::(&conn) - .unwrap(); + let version3 = version_find_first(&conn, version.id); assert_eq!(version3.downloads, 2); }