Skip to content

Commit 1292f7f

Browse files
committed
Update max_version if max_version is null when publishing new version
1 parent 6800937 commit 1292f7f

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

src/krate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ impl Crate {
385385
}
386386
let zero = semver::Version::parse("0.0.0").unwrap();
387387
let new_max = match self.max_version {
388+
None => true,
388389
Some(ref max_version) if *ver > *max_version || *max_version == zero => true,
389390
_ => false,
390391
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
===REQUEST 339
2+
PUT http://alexcrichton-test.s3.amazonaws.com/crates/fyk_max/fyk_max-1.0.0.crate HTTP/1.1
3+
Accept: */*
4+
Proxy-Connection: Keep-Alive
5+
Authorization: AWS AKIAJF3GEK7N44BACDZA:GDxGb6r3SIqo9wXuzHrgMNWekwk=
6+
Content-Length: 0
7+
Host: alexcrichton-test.s3.amazonaws.com
8+
Content-Type: application/x-tar
9+
Date: Sun, 28 Jun 2015 14:07:17 -0700
10+
11+
12+
===RESPONSE 258
13+
HTTP/1.1 200
14+
x-amz-request-id: CB0E925D8E3AB3E8
15+
x-amz-id-2: SiaMwszM1p2TzXlLauvZ6kRKcUCg7HoyBW29vts42w9ArrLwkJWl8vuvPuGFkpM6XGH+YXN852g=
16+
date: Sun, 28 Jun 2015 21:07:51 GMT
17+
etag: "d41d8cd98f00b204e9800998ecf8427e"
18+
content-length: 0
19+
server: AmazonS3
20+
21+
22+
===REQUEST 339
23+
PUT http://alexcrichton-test.s3.amazonaws.com/crates/fyk_max/fyk_max-2.0.0.crate HTTP/1.1
24+
Accept: */*
25+
Proxy-Connection: Keep-Alive
26+
Authorization: AWS AKIAJF3GEK7N44BACDZA:GDxGb6r3SIqo9wXuzHrgMNWekwk=
27+
Content-Length: 0
28+
Host: alexcrichton-test.s3.amazonaws.com
29+
Content-Type: application/x-tar
30+
Date: Sun, 28 Jun 2015 14:07:17 -0700
31+
32+
33+
===RESPONSE 258
34+
HTTP/1.1 200
35+
x-amz-request-id: CB0E925D8E3AB3E8
36+
x-amz-id-2: SiaMwszM1p2TzXlLauvZ6kRKcUCg7HoyBW29vts42w9ArrLwkJWl8vuvPuGFkpM6XGH+YXN852g=
37+
date: Sun, 28 Jun 2015 21:07:51 GMT
38+
etag: "d41d8cd98f00b204e9800998ecf8427e"
39+
content-length: 0
40+
server: AmazonS3
41+

src/tests/krate.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,53 @@ fn yank_max_version() {
958958
assert_eq!(json.krate.max_version.unwrap(), "2.0.0");
959959
}
960960

961+
#[test]
962+
fn publish_after_yank_max_version() {
963+
#[derive(RustcDecodable)]
964+
struct O {
965+
ok: bool,
966+
}
967+
let (_b, app, middle) = ::app();
968+
969+
// Upload a new crate
970+
let mut req = ::new_req(app, "fyk_max", "1.0.0");
971+
::mock_user(&mut req, ::user("foo"));
972+
let mut response = ok_resp!(middle.call(&mut req));
973+
974+
// double check the max version
975+
let json: GoodCrate = ::json(&mut response);
976+
assert!(json.krate.max_version.is_some());
977+
assert_eq!(json.krate.max_version.unwrap(), "1.0.0");
978+
979+
// yank version 1.0.0
980+
let mut r = ok_resp!(middle.call(req.with_method(Method::Delete)
981+
.with_path("/api/v1/crates/fyk_max/1.0.0/yank")));
982+
assert!(::json::<O>(&mut r).ok);
983+
let mut response = ok_resp!(middle.call(req.with_method(Method::Get)
984+
.with_path("/api/v1/crates/fyk_max")));
985+
let json: CrateResponse = ::json(&mut response);
986+
assert!(json.krate.max_version.is_none());
987+
988+
// add version 2.0.0
989+
let body = ::new_req_body_version_2(::krate("fyk_max"));
990+
let mut response = ok_resp!(middle.call(req.with_path("/api/v1/crates/new")
991+
.with_method(Method::Put)
992+
.with_body(&body)));
993+
let json: GoodCrate = ::json(&mut response);
994+
assert!(json.krate.max_version.is_some());
995+
assert_eq!(json.krate.max_version.unwrap(), "2.0.0");
996+
997+
// unyank version 1.0.0
998+
let mut r = ok_resp!(middle.call(req.with_method(Method::Put)
999+
.with_path("/api/v1/crates/fyk_max/1.0.0/unyank")));
1000+
assert!(::json::<O>(&mut r).ok);
1001+
let mut response = ok_resp!(middle.call(req.with_method(Method::Get)
1002+
.with_path("/api/v1/crates/fyk_max")));
1003+
let json: CrateResponse = ::json(&mut response);
1004+
assert!(json.krate.max_version.is_some());
1005+
assert_eq!(json.krate.max_version.unwrap(), "2.0.0");
1006+
}
1007+
9611008
#[test]
9621009
fn bad_keywords() {
9631010
let (_b, app, middle) = ::app();

0 commit comments

Comments
 (0)