Skip to content

Commit a2eb1f9

Browse files
Merge #948
948: Stop showing documentation link when documentation is removed from Cargo.toml r=carols10cents Fixes #945 This is exactly the fix suggested in #945 (comment) but applied to the `NewCrate` struct instead of the `Crate` struct since `NewCrate` is actually what gets stored in the DB. Problems with this fix: * The webpage for the crates that are affected by this will only get updated when they next publish * The version specific webpages for the crate do not show a documentation link even if that crate once had a documentation key * This is because we do not track this metadata per version and should probably be a separate issue
2 parents 487166c + 59da18d commit a2eb1f9

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

src/models/krate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type ByName<'a> = diesel::dsl::Filter<All, WithName<'a>>;
8989

9090
#[derive(Insertable, AsChangeset, Default, Debug)]
9191
#[table_name = "crates"]
92+
#[changeset_options(treat_none_as_null = "true")]
9293
#[primary_key(name, max_upload_size)] // This is actually just to skip updating them
9394
pub struct NewCrate<'a> {
9495
pub name: &'a str,

src/tests/all.rs

+11
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,17 @@ fn new_req(app: Arc<App>, krate: &str, version: &str) -> MockRequest {
548548
new_req_full(app, ::krate(krate), version, Vec::new())
549549
}
550550

551+
fn new_req_with_documentation(
552+
app: Arc<App>,
553+
krate: &str,
554+
version: &str,
555+
documentation: &str,
556+
) -> MockRequest {
557+
let mut krate = ::krate(krate);
558+
krate.documentation = Some(documentation.into());
559+
new_req_full(app, krate, version, Vec::new())
560+
}
561+
551562
fn new_req_full(
552563
app: Arc<App>,
553564
krate: Crate,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"request":{"uri":"http://alexcrichton-test.s3.amazonaws.com/crates/docscrate/docscrate-0.2.1.crate","method":"PUT","headers":[["Proxy-Connection","Keep-Alive"],["Content-Type","application/x-tar"],["Accept","*/*"],["Date","Fri, 15 Sep 2017 07:53:06 -0700"],["Authorization","AWS AKIAICL5IWUZYWWKA7JA:RkpxRf+NUDyzjWrEMc1ikasbtZI="],["Content-Length","35"],["Host","alexcrichton-test.s3.amazonaws.com"]],"body":[31,139,8,0,0,0,0,0,0,255,237,192,1,1,0,0,0,130,32,255,175,110,72,80,192,171,1,46,175,181,239,0,4,0,0]},"response":{"status":200,"headers":[["ETag","\"f9016ad360cebb4fe2e6e96e5949f022\""],["Content-Length","0"],["Date","Fri, 15 Sep 2017 14:53:07 GMT"],["x-amz-id-2","Es2wWCc+tXkMbbp+bEcjLFQn6yGqPeAUiBI5XqXZ8mAZUIpe7vYiCfBfoU727trNpEFMymyhgZY="],["Server","AmazonS3"],["x-amz-request-id","98298F12367C7A0B"]],"body":[]}},{"request":{"uri":"http://alexcrichton-test.s3.amazonaws.com/crates/docscrate/docscrate-0.2.2.crate","method":"PUT","headers":[["Date","Fri, 15 Sep 2017 07:53:06 -0700"],["Authorization","AWS AKIAICL5IWUZYWWKA7JA:umuWs3XoGqsDipgMq04QAhq9Spc="],["Content-Type","application/x-tar"],["Host","alexcrichton-test.s3.amazonaws.com"],["Accept","*/*"],["Proxy-Connection","Keep-Alive"],["Content-Length","35"]],"body":[31,139,8,0,0,0,0,0,0,255,237,192,1,1,0,0,0,130,32,255,175,110,72,80,192,171,1,46,175,181,239,0,4,0,0]},"response":{"status":200,"headers":[["x-amz-request-id","2E4EDB9109077234"],["x-amz-id-2","gnBA5fngpIAF7AVe+goe2YZkL6gB7yRp25LNjBl7wqyMNeIXGMLTyWd/46bkoVNv/S9t9BZ5IB4="],["ETag","\"f9016ad360cebb4fe2e6e96e5949f022\""],["Date","Fri, 15 Sep 2017 14:53:07 GMT"],["Server","AmazonS3"],["Content-Length","0"]],"body":[]}}]

src/tests/krate.rs

+60
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,66 @@ fn publish_after_yank_max_version() {
15731573
assert_eq!(json.krate.max_version, "2.0.0");
15741574
}
15751575

1576+
#[test]
1577+
fn publish_after_removing_documentation() {
1578+
let (_b, app, middle) = ::app();
1579+
1580+
let user;
1581+
1582+
// 1. Start with a crate with no documentation
1583+
{
1584+
let conn = app.diesel_database.get().unwrap();
1585+
user = ::new_user("foo").create_or_update(&conn).unwrap();
1586+
::CrateBuilder::new("docscrate", user.id)
1587+
.version("0.2.0")
1588+
.expect_build(&conn);
1589+
}
1590+
1591+
// Verify that crates start without any documentation so the next assertion can *prove*
1592+
// that it was the one that added the documentation
1593+
{
1594+
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/crates/docscrate");
1595+
let mut response = ok_resp!(middle.call(&mut req));
1596+
let json: CrateResponse = ::json(&mut response);
1597+
assert_eq!(json.krate.documentation, None);
1598+
}
1599+
1600+
// 2. Add documentation
1601+
{
1602+
let mut req =
1603+
::new_req_with_documentation(Arc::clone(&app), "docscrate", "0.2.1", "http://foo.rs");
1604+
::sign_in_as(&mut req, &user);
1605+
let mut response = ok_resp!(middle.call(&mut req));
1606+
let json: GoodCrate = ::json(&mut response);
1607+
assert_eq!(json.krate.documentation, Some("http://foo.rs".to_owned()));
1608+
}
1609+
1610+
// Ensure latest version also has the same documentation
1611+
{
1612+
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/crates/docscrate");
1613+
let mut response = ok_resp!(middle.call(&mut req));
1614+
let json: CrateResponse = ::json(&mut response);
1615+
assert_eq!(json.krate.documentation, Some("http://foo.rs".to_owned()));
1616+
}
1617+
1618+
// 3. Remove the documentation
1619+
{
1620+
let mut req = ::new_req(Arc::clone(&app), "docscrate", "0.2.2");
1621+
::sign_in_as(&mut req, &user);
1622+
let mut response = ok_resp!(middle.call(&mut req));
1623+
let json: GoodCrate = ::json(&mut response);
1624+
assert_eq!(json.krate.documentation, None);
1625+
}
1626+
1627+
// Ensure latest version no longer has documentation
1628+
{
1629+
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/crates/docscrate");
1630+
let mut response = ok_resp!(middle.call(&mut req));
1631+
let json: CrateResponse = ::json(&mut response);
1632+
assert_eq!(json.krate.documentation, None);
1633+
}
1634+
}
1635+
15761636
#[test]
15771637
fn bad_keywords() {
15781638
let (_b, app, middle) = ::app();

0 commit comments

Comments
 (0)