Skip to content

Commit 2ca8ecc

Browse files
committed
Expose TopVersions::highest_stable as max_stable_version
1 parent ad7f729 commit 2ca8ecc

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/models/krate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ impl Crate {
357357
.map(|v| v.to_string())
358358
.unwrap_or_else(|| "0.0.0".to_string());
359359

360+
let max_stable_version = top_versions.highest_stable.as_ref().map(|v| v.to_string());
361+
360362
EncodableCrate {
361363
id: name.clone(),
362364
name: name.clone(),
@@ -370,6 +372,7 @@ impl Crate {
370372
badges,
371373
max_version,
372374
newest_version,
375+
max_stable_version,
373376
documentation,
374377
homepage,
375378
exact_match,

src/tests/krate/search.rs

+21
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,27 @@ fn yanked_versions_are_not_considered_for_max_version() {
508508
assert_eq!(json.crates[0].max_version, "1.0.0");
509509
}
510510

511+
#[test]
512+
fn max_stable_version() {
513+
let (app, anon, user) = TestApp::init().with_user();
514+
let user = user.as_model();
515+
516+
app.db(|conn| {
517+
CrateBuilder::new("foo", user.id)
518+
.description("foo")
519+
.version("0.3.0")
520+
.version("1.0.0")
521+
.version(VersionBuilder::new("1.1.0").yanked(true))
522+
.version("2.0.0-beta.1")
523+
.version("0.3.1")
524+
.expect_build(conn);
525+
});
526+
527+
let json = anon.search("q=foo");
528+
assert_eq!(json.meta.total, 1);
529+
assert_eq!(json.crates[0].max_stable_version, Some("1.0.0".to_string()));
530+
}
531+
511532
/* Given two crates, one with downloads less than 90 days ago, the
512533
other with all downloads greater than 90 days ago, check that
513534
the order returned is by recent downloads, descending. Check

src/views.rs

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ pub struct EncodableCrate {
156156
// NOTE: Used by shields.io, altering `max_version` requires a PR with shields.io
157157
pub max_version: String,
158158
pub newest_version: String, // Most recently updated version, which may not be max
159+
pub max_stable_version: Option<String>,
159160
pub description: Option<String>,
160161
pub homepage: Option<String>,
161162
pub documentation: Option<String>,
@@ -510,6 +511,7 @@ mod tests {
510511
recent_downloads: None,
511512
max_version: "".to_string(),
512513
newest_version: "".to_string(),
514+
max_stable_version: None,
513515
description: None,
514516
homepage: None,
515517
documentation: None,

0 commit comments

Comments
 (0)