Skip to content

Commit f10bcb5

Browse files
committed
Fixes #945
1 parent 31a5a35 commit f10bcb5

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

src/krate/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub struct CrateLinks {
130130

131131
#[derive(Insertable, AsChangeset, Default, Debug)]
132132
#[table_name = "crates"]
133+
#[changeset_options(treat_none_as_null = "true")]
133134
#[primary_key(name, max_upload_size)] // This is actually just to skip updating them
134135
pub struct NewCrate<'a> {
135136
pub name: &'a str,

src/tests/all.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,17 @@ fn new_req(app: Arc<App>, krate: &str, version: &str) -> MockRequest {
544544
new_req_full(app, ::krate(krate), version, Vec::new())
545545
}
546546

547+
fn new_req_with_documentation(
548+
app: Arc<App>,
549+
krate: &str,
550+
version: &str,
551+
documentation: Option<String>,
552+
) -> MockRequest {
553+
let mut krate = ::krate(krate);
554+
krate.documentation = documentation;
555+
new_req_full(app, krate, version, Vec::new())
556+
}
557+
547558
fn new_req_full(
548559
app: Arc<App>,
549560
krate: Crate,
Lines changed: 1 addition & 0 deletions
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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,70 @@ fn publish_after_yank_max_version() {
15761576
assert_eq!(json.krate.max_version, "2.0.0");
15771577
}
15781578

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

0 commit comments

Comments
 (0)