Skip to content

Commit

Permalink
Revert "Don't let release activity panic with zero releases"
Browse files Browse the repository at this point in the history
This reverts commit c458bb9.
  • Loading branch information
Joshua Nelson committed Jul 7, 2020
1 parent af9555c commit a51926f
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 7 deletions.
122 changes: 122 additions & 0 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,48 @@ impl CrateDetails {
.find(|release| !release.yanked)
.unwrap_or(&self.releases[0])
}

#[cfg(test)]
pub fn default_tester(release_time: DateTime<Utc>) -> Self {
Self {
name: "rcc".to_string(),
version: "100.0.0".to_string(),
description: None,
authors: vec![],
owners: vec![],
authors_json: None,
dependencies: None,
readme: None,
rustdoc: None,
release_time,
build_status: true,
last_successful_build: None,
rustdoc_status: true,
repository_url: None,
homepage_url: None,
keywords: None,
yanked: false,
have_examples: true,
target_name: "x86_64-unknown-linux-gnu".to_string(),
releases: vec![],
github: true,
github_stars: None,
github_forks: None,
github_issues: None,
metadata: MetaData {
name: "serde".to_string(),
version: "1.0.0".to_string(),
description: Some("serde does stuff".to_string()),
target_name: None,
rustdoc_status: true,
default_target: "x86_64-unknown-linux-gnu".to_string(),
},
is_library: true,
doc_targets: vec![],
license: None,
documentation_url: None,
}
}
}

fn map_to_release(conn: &Connection, crate_id: i32, version: String) -> Release {
Expand Down Expand Up @@ -309,7 +351,9 @@ pub fn crate_details_handler(req: &mut Request) -> IronResult<Response> {
mod tests {
use super::*;
use crate::test::TestDatabase;
use chrono::Utc;
use failure::Error;
use serde_json::json;

fn assert_last_successful_build_equals(
db: &TestDatabase,
Expand Down Expand Up @@ -554,4 +598,82 @@ mod tests {
Ok(())
})
}

#[test]
fn serialize_crate_details() {
let time = Utc::now();
let mut details = CrateDetails::default_tester(time);

let mut correct_json = json!({
"name": "rcc",
"version": "100.0.0",
"description": null,
"authors": [],
"owners": [],
"authors_json": null,
"dependencies": null,
"release_time": super::super::duration_to_str(time),
"build_status": true,
"last_successful_build": null,
"rustdoc_status": true,
"repository_url": null,
"homepage_url": null,
"keywords": null,
"have_examples": true,
"target_name": "x86_64-unknown-linux-gnu",
"releases": [],
"github": true,
"yanked": false,
"github_stars": null,
"github_forks": null,
"github_issues": null,
"metadata": {
"name": "serde",
"version": "1.0.0",
"description": "serde does stuff",
"target_name": null,
"rustdoc_status": true,
"default_target": "x86_64-unknown-linux-gnu"
},
"is_library": true,
"doc_targets": [],
"license": null,
"documentation_url": null
});

assert_eq!(correct_json, serde_json::to_value(&details).unwrap());

let authors = vec![("Somebody".to_string(), "[email protected]".to_string())];
let owners = vec![("Owner".to_string(), "[email protected]".to_string())];
let description = "serde does stuff".to_string();

correct_json["description"] = Value::String(description.clone());
correct_json["owners"] = serde_json::to_value(&owners).unwrap();
correct_json["authors_json"] = serde_json::to_value(&authors).unwrap();
correct_json["authors"] = serde_json::to_value(&authors).unwrap();

details.description = Some(description);
details.owners = owners;
details.authors_json = Some(serde_json::to_value(&authors).unwrap());
details.authors = authors;

assert_eq!(correct_json, serde_json::to_value(&details).unwrap());
}

#[test]
fn serialize_releases() {
let release = Release {
version: "idkman".to_string(),
build_status: true,
yanked: true,
};

let correct_json = json!({
"version": "idkman",
"build_status": true,
"yanked": true,
});

assert_eq!(correct_json, serde_json::to_value(&release).unwrap());
}
}
12 changes: 5 additions & 7 deletions templates/releases/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
},
xAxis: {
categories: [
{% if activity_data.dates -%}
{%- for date in activity_data.dates -%}
{{ "'" ~ date ~ "'," }}
{%- endfor -%}
{%- endif %}
{% for date in activity_data.dates %}
{{ "'" ~ date ~ "'," }}
{% endfor %}
]
},
yAxis: {
Expand All @@ -49,10 +47,10 @@
},
series: [{
name: 'Releases',
data: [{{ activity_data.counts | default(value=[]) | join(sep=", ") }}]
data: [{{ activity_data.counts | join(sep=", ") }}]
}, {
name: 'Build Failures',
data: [{{ activity_data.failures | default(value=[]) | join(sep=", ") }}]
data: [{{ activity_data.failures | join(sep=", ") }}]
}]
});
</script>
Expand Down
Empty file removed test.txt
Empty file.

0 comments on commit a51926f

Please sign in to comment.