Skip to content

Commit

Permalink
Merge pull request #742 from marti1125/master
Browse files Browse the repository at this point in the history
add new badges #704
  • Loading branch information
carols10cents authored Jul 15, 2017
2 parents 66d5d92 + 14f1b4c commit d11819c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ pub enum Badge {
branch: Option<String>,
service: Option<String>,
},
Maintenance { value: MaintenanceValue },
}

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum MaintenanceValue {
ActivelyDeveloped,
PassivelyMaintained,
AsIs,
None,
Experimental,
LookingForMaintainer,
Deprecated,
}

#[derive(PartialEq, Debug, Serialize, Deserialize)]
Expand Down
75 changes: 74 additions & 1 deletion src/tests/badge.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cargo_registry::app::App;
use cargo_registry::badge::Badge;
use cargo_registry::badge::{Badge, MaintenanceValue};
use cargo_registry::krate::Crate;

use std::collections::HashMap;
Expand All @@ -22,6 +22,8 @@ struct BadgeRef {
coveralls_attributes: HashMap<String, String>,
circle_ci: Badge,
circle_ci_attributes: HashMap<String, String>,
maintenance: Badge,
maintenance_attributes: HashMap<String, String>,
}

fn set_up() -> (Arc<App>, Crate, BadgeRef) {
Expand Down Expand Up @@ -106,6 +108,13 @@ fn set_up() -> (Arc<App>, Crate, BadgeRef) {
badge_attributes_circle_ci.insert(String::from("branch"), String::from("beta"));
badge_attributes_circle_ci.insert(String::from("repository"), String::from("rust-lang/rust"));

let maintenance = Badge::Maintenance { value: MaintenanceValue::LookingForMaintainer };
let mut maintenance_attributes = HashMap::new();
maintenance_attributes.insert(
String::from("value"),
String::from("looking-for-maintainer"),
);

let badges = BadgeRef {
appveyor: appveyor,
appveyor_attributes: badge_attributes_appveyor,
Expand All @@ -124,6 +133,8 @@ fn set_up() -> (Arc<App>, Crate, BadgeRef) {
coveralls_attributes: badge_attributes_coveralls,
circle_ci: circle_ci,
circle_ci_attributes: badge_attributes_circle_ci,
maintenance,
maintenance_attributes,
};
(app, krate, badges)
}
Expand Down Expand Up @@ -247,6 +258,21 @@ fn update_add_circle_ci() {
assert_eq!(krate.badges(&conn).unwrap(), vec![test_badges.circle_ci]);
}

#[test]
fn update_add_maintenance() {
// Add a maintenance badge
let (app, krate, test_badges) = set_up();
let conn = app.diesel_database.get().unwrap();

let mut badges = HashMap::new();
badges.insert(
String::from("maintenance"),
test_badges.maintenance_attributes,
);
Badge::update_crate(&conn, &krate, Some(&badges)).unwrap();
assert_eq!(krate.badges(&conn).unwrap(), vec![test_badges.maintenance]);
}

#[test]
fn replace_badge() {
// Replacing one badge with another
Expand Down Expand Up @@ -480,6 +506,53 @@ fn circle_ci_required_keys() {
assert_eq!(krate.badges(&conn).unwrap(), vec![]);
}

#[test]
fn maintenance_required_keys() {
// Add a maintenance badge missing a required field
let (app, krate, mut test_badges) = set_up();
let conn = app.diesel_database.get().unwrap();

let mut badges = HashMap::new();

// Value is a required key
test_badges.maintenance_attributes.remove("value");
badges.insert(
String::from("maintenance"),
test_badges.maintenance_attributes,
);

let invalid_badges = Badge::update_crate(&conn, &krate, Some(&badges)).unwrap();
assert_eq!(invalid_badges.len(), 1);
assert!(invalid_badges.contains(&"maintenance"));
assert_eq!(krate.badges(&conn).unwrap(), vec![]);
}

#[test]
fn maintenance_invalid_values() {
// Add a maintenance badge with an invalid value
let (app, krate, mut test_badges) = set_up();
let conn = app.diesel_database.get().unwrap();

let mut badges = HashMap::new();

// "totes broken" is not a recognized value
test_badges.maintenance_attributes.insert(
String::from("value"),
String::from(
"totes broken",
),
);
badges.insert(
String::from("maintenance"),
test_badges.maintenance_attributes,
);

let invalid_badges = Badge::update_crate(&conn, &krate, Some(&badges)).unwrap();
assert_eq!(invalid_badges.len(), 1);
assert!(invalid_badges.contains(&"maintenance"));
assert_eq!(krate.badges(&conn).unwrap(), vec![]);
}

#[test]
fn unknown_badge() {
// Add an unknown badge
Expand Down

0 comments on commit d11819c

Please sign in to comment.