Skip to content

Commit

Permalink
Extract a test helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Feb 8, 2019
1 parent dccc89f commit 8cfa142
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/bin/update-downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Version>(conn)
.unwrap()
}

#[test]
fn increment_a_little() {
use diesel::dsl::*;
Expand Down Expand Up @@ -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::<Version>(&conn)
.unwrap();
let version_before = version_find_first(&conn, version.id);
let krate_before = Crate::all()
.filter(crates::id.eq(krate.id))
.first::<Crate>(&conn)
.unwrap();
crate::update(&conn).unwrap();
let version2 = versions::table
.find(version.id)
.select(cargo_registry::models::version::ALL_COLUMNS)
.first::<Version>(&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()
Expand 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::<Version>(&conn)
.unwrap();
let version3 = version_find_first(&conn, version.id);
assert_eq!(version3.downloads, 2);
}

Expand Down

0 comments on commit 8cfa142

Please sign in to comment.