message: last_successful_build: add test case if no build succeeded; slight refactor
diff: @@ -219,7 +219,7 @@ impl CrateDetails {
  }
  // retrieve last successful build if build failed
  - if crate_details.build_status == false {
  + if !crate_details.build_status {
  let rows = conn.query(
  "SELECT version
  FROM releases
  @@ -278,8 +278,6 @@ mod tests {
  use super::*;
  use failure::Error;
  - #[test]
  - fn test_last_successful_build() {
  fn last_successful_build_equals(
  conn: &Connection,
  package: &str,
  @@ -291,8 +289,10 @@ mod tests {
  .ok_or(failure::err_msg("could not fetch crate details"))?;
  Ok(details.last_successful_build == expected_last_successful_build)
  - };
  + }
  + #[test]
  + fn test_last_successful_build() {
  crate::test::with_database(|db| {
  // Create some releases in the database, of which the last release failed to build
  db.fake_release()
  @@ -316,4 +316,26 @@ mod tests {
  Ok(())
  });
  }
  +
  + #[test]
  + fn test_last_successful_build_but_none_succeeded() {
  + crate::test::with_database(|db| {
  + // Create some releases in the database, of which all failed to build
  + db.fake_release()
  + .name("foo")
  + .version("0.0.1")
  + .build_result_successful(false)
  + .create()?;
  + db.fake_release()
  + .name("foo")
  + .version("0.0.2")
  + .build_result_successful(false)
  + .create()?;
  +
  + assert!(last_successful_build_equals(&db.conn(), "foo", "0.0.1", None)?);
  + assert!(last_successful_build_equals(&db.conn(), "foo", "0.0.2", None)?);
  +
  + Ok(())
  + });
  + }
  }
  