Skip to content

Commit 6ee2bef

Browse files
committed
Fixup all the tests
1 parent 40f51a7 commit 6ee2bef

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/bin/migrate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ fn migrations() -> Vec<Migration> {
455455
"ALTER TABLE crate_owners ALTER owner_kind SET DEFAULT 0",
456456
),
457457
Migration::add_table(20150804170128, "teams", "
458-
id SERIAL PRIMARY KEY
459-
name VARCHAR NOT NULL UNIQUE
458+
id SERIAL PRIMARY KEY,
459+
name VARCHAR NOT NULL UNIQUE,
460460
github_id INTEGER NOT NULL UNIQUE
461461
"),
462462
Migration::run(20150804170129,

src/krate.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ impl Crate {
175175
})));
176176

177177
try!(conn.execute("INSERT INTO crate_owners
178-
(crate_id, owner_id, created_at, updated_at, deleted)
179-
VALUES ($1, $2, $3, $3, FALSE)",
178+
(crate_id, owner_id, created_by, created_at,
179+
updated_at, deleted, owner_kind)
180+
VALUES ($1, $2, $2, $3, $3, FALSE, 0)",
180181
&[&ret.id, &user_id, &now]));
181182
return Ok(ret);
182183

@@ -334,8 +335,8 @@ impl Crate {
334335
}));
335336
try!(conn.execute("UPDATE crate_owners
336337
SET deleted = TRUE, updated_at = $1
337-
WHERE crate_id = $2 AND owner_id = $3",
338-
&[&::now(), &self.id, &owner.id()]));
338+
WHERE crate_id = $2 AND owner_id = $3 AND owner_kind = $4",
339+
&[&::now(), &self.id, &owner.id(), &owner.kind()]));
339340
Ok(())
340341
}
341342

@@ -492,13 +493,15 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
492493
(format!("SELECT crates.* FROM crates
493494
INNER JOIN crate_owners
494495
ON crate_owners.crate_id = crates.id
495-
WHERE crate_owners.user_id = $1 {} \
496+
WHERE crate_owners.owner_id = $1
497+
AND crate_owners.owner_kind = 0 {}
496498
LIMIT $2 OFFSET $3",
497499
sort_sql),
498500
"SELECT COUNT(crates.*) FROM crates
499501
INNER JOIN crate_owners
500502
ON crate_owners.crate_id = crates.id
501-
WHERE crate_owners.user_id = $1".to_string())
503+
WHERE crate_owners.owner_id = $1 \
504+
AND crate_owners.owner_kind = 0".to_string())
502505
})
503506
}).or_else(|| {
504507
query.get("following").map(|_| {
@@ -647,7 +650,7 @@ pub fn new(req: &mut Request) -> CargoResult<Response> {
647650
&new_crate.license_file));
648651

649652
let owners = try!(krate.owners(try!(req.tx())));
650-
if try!(rights(&owners, &user)) >= Rights::Publish {
653+
if try!(rights(&owners, &user)) < Rights::Publish {
651654
return Err(human("crate name has already been claimed by \
652655
another user"))
653656
}
@@ -1001,12 +1004,12 @@ fn modify_owners(req: &mut Request, add: bool) -> CargoResult<Response> {
10011004
}
10021005
}
10031006

1004-
#[derive(RustcDecodable)] struct Request { owners: Vec<String> }
1007+
#[derive(RustcDecodable)] struct Request { users: Vec<String> }
10051008
let request: Request = try!(json::decode(&body).map_err(|_| {
10061009
human("invalid json request")
10071010
}));
10081011

1009-
for name in &request.owners {
1012+
for name in &request.users {
10101013
if add {
10111014
if owners.iter().any(|owner| owner.name() == *name) {
10121015
return Err(human(format!("`{}` is already an owner", name)))

src/owner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {Model, User};
22
use util::{RequestUtils, CargoResult, internal, ChainError, human};
33
use db::Connection;
44
use curl::http;
5-
use pg;
5+
use pg::rows::Row;
66
use rustc_serialize::json;
77
use util::errors::NotFound;
88
use std::str;
@@ -203,7 +203,7 @@ impl Team {
203203
}
204204

205205
impl Model for Team {
206-
fn from_row(row: &pg::Row) -> Self {
206+
fn from_row(row: &Row) -> Self {
207207
Team {
208208
cargo_id: row.get("id"),
209209
name: row.get("name"),

0 commit comments

Comments
 (0)