Skip to content

Commit c458bb9

Browse files
KixironJoshua Nelson
authored andcommitted
Don't let release activity panic with zero releases
1 parent 55b85cf commit c458bb9

File tree

3 files changed

+7
-127
lines changed

3 files changed

+7
-127
lines changed

src/web/crate_details.rs

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -238,48 +238,6 @@ impl CrateDetails {
238238
.find(|release| !release.yanked)
239239
.unwrap_or(&self.releases[0])
240240
}
241-
242-
#[cfg(test)]
243-
pub fn default_tester(release_time: DateTime<Utc>) -> Self {
244-
Self {
245-
name: "rcc".to_string(),
246-
version: "100.0.0".to_string(),
247-
description: None,
248-
authors: vec![],
249-
owners: vec![],
250-
authors_json: None,
251-
dependencies: None,
252-
readme: None,
253-
rustdoc: None,
254-
release_time,
255-
build_status: true,
256-
last_successful_build: None,
257-
rustdoc_status: true,
258-
repository_url: None,
259-
homepage_url: None,
260-
keywords: None,
261-
yanked: false,
262-
have_examples: true,
263-
target_name: "x86_64-unknown-linux-gnu".to_string(),
264-
releases: vec![],
265-
github: true,
266-
github_stars: None,
267-
github_forks: None,
268-
github_issues: None,
269-
metadata: MetaData {
270-
name: "serde".to_string(),
271-
version: "1.0.0".to_string(),
272-
description: Some("serde does stuff".to_string()),
273-
target_name: None,
274-
rustdoc_status: true,
275-
default_target: "x86_64-unknown-linux-gnu".to_string(),
276-
},
277-
is_library: true,
278-
doc_targets: vec![],
279-
license: None,
280-
documentation_url: None,
281-
}
282-
}
283241
}
284242

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

358314
fn assert_last_successful_build_equals(
359315
db: &TestDatabase,
@@ -598,82 +554,4 @@ mod tests {
598554
Ok(())
599555
})
600556
}
601-
602-
#[test]
603-
fn serialize_crate_details() {
604-
let time = Utc::now();
605-
let mut details = CrateDetails::default_tester(time);
606-
607-
let mut correct_json = json!({
608-
"name": "rcc",
609-
"version": "100.0.0",
610-
"description": null,
611-
"authors": [],
612-
"owners": [],
613-
"authors_json": null,
614-
"dependencies": null,
615-
"release_time": super::super::duration_to_str(time),
616-
"build_status": true,
617-
"last_successful_build": null,
618-
"rustdoc_status": true,
619-
"repository_url": null,
620-
"homepage_url": null,
621-
"keywords": null,
622-
"have_examples": true,
623-
"target_name": "x86_64-unknown-linux-gnu",
624-
"releases": [],
625-
"github": true,
626-
"yanked": false,
627-
"github_stars": null,
628-
"github_forks": null,
629-
"github_issues": null,
630-
"metadata": {
631-
"name": "serde",
632-
"version": "1.0.0",
633-
"description": "serde does stuff",
634-
"target_name": null,
635-
"rustdoc_status": true,
636-
"default_target": "x86_64-unknown-linux-gnu"
637-
},
638-
"is_library": true,
639-
"doc_targets": [],
640-
"license": null,
641-
"documentation_url": null
642-
});
643-
644-
assert_eq!(correct_json, serde_json::to_value(&details).unwrap());
645-
646-
let authors = vec![("Somebody".to_string(), "[email protected]".to_string())];
647-
let owners = vec![("Owner".to_string(), "[email protected]".to_string())];
648-
let description = "serde does stuff".to_string();
649-
650-
correct_json["description"] = Value::String(description.clone());
651-
correct_json["owners"] = serde_json::to_value(&owners).unwrap();
652-
correct_json["authors_json"] = serde_json::to_value(&authors).unwrap();
653-
correct_json["authors"] = serde_json::to_value(&authors).unwrap();
654-
655-
details.description = Some(description);
656-
details.owners = owners;
657-
details.authors_json = Some(serde_json::to_value(&authors).unwrap());
658-
details.authors = authors;
659-
660-
assert_eq!(correct_json, serde_json::to_value(&details).unwrap());
661-
}
662-
663-
#[test]
664-
fn serialize_releases() {
665-
let release = Release {
666-
version: "idkman".to_string(),
667-
build_status: true,
668-
yanked: true,
669-
};
670-
671-
let correct_json = json!({
672-
"version": "idkman",
673-
"build_status": true,
674-
"yanked": true,
675-
});
676-
677-
assert_eq!(correct_json, serde_json::to_value(&release).unwrap());
678-
}
679557
}

templates/releases/activity.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
},
3131
xAxis: {
3232
categories: [
33-
{% for date in activity_data.dates %}
34-
{{ "'" ~ date ~ "'," }}
35-
{% endfor %}
33+
{% if activity_data.dates -%}
34+
{%- for date in activity_data.dates -%}
35+
{{ "'" ~ date ~ "'," }}
36+
{%- endfor -%}
37+
{%- endif %}
3638
]
3739
},
3840
yAxis: {
@@ -47,10 +49,10 @@
4749
},
4850
series: [{
4951
name: 'Releases',
50-
data: [{{ activity_data.counts | join(sep=", ") }}]
52+
data: [{{ activity_data.counts | default(value=[]) | join(sep=", ") }}]
5153
}, {
5254
name: 'Build Failures',
53-
data: [{{ activity_data.failures | join(sep=", ") }}]
55+
data: [{{ activity_data.failures | default(value=[]) | join(sep=", ") }}]
5456
}]
5557
});
5658
</script>

test.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)