|
|
|
@ -249,7 +249,7 @@ mod tests {
|
|
|
|
|
posts::NewPost,
|
|
|
|
|
safe_string::SafeString,
|
|
|
|
|
tags::Tag,
|
|
|
|
|
tests::{db, rockets},
|
|
|
|
|
tests::db,
|
|
|
|
|
users::tests as userTests,
|
|
|
|
|
};
|
|
|
|
|
use diesel::Connection;
|
|
|
|
@ -258,63 +258,69 @@ mod tests {
|
|
|
|
|
fn test_timeline() {
|
|
|
|
|
let conn = &db();
|
|
|
|
|
conn.test_transaction::<_, (), _>(|| {
|
|
|
|
|
let users = userTests::fill_database(conn);
|
|
|
|
|
let users = userTests::fill_database(&conn);
|
|
|
|
|
|
|
|
|
|
let mut tl1_u1 = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"my timeline".to_owned(),
|
|
|
|
|
"all".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
List::new(conn, "languages I speak", Some(&users[1]), ListType::Prefix).unwrap();
|
|
|
|
|
List::new(
|
|
|
|
|
&conn,
|
|
|
|
|
"languages I speak",
|
|
|
|
|
Some(&users[1]),
|
|
|
|
|
ListType::Prefix,
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let tl2_u1 = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"another timeline".to_owned(),
|
|
|
|
|
"followed".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let tl1_u2 = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[1].id,
|
|
|
|
|
"english posts".to_owned(),
|
|
|
|
|
"lang in \"languages I speak\"".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let tl1_instance = Timeline::new_for_instance(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
"english posts".to_owned(),
|
|
|
|
|
"license in [cc]".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
assert_eq!(tl1_u1, Timeline::get(conn, tl1_u1.id).unwrap());
|
|
|
|
|
assert_eq!(tl1_u1, Timeline::get(&conn, tl1_u1.id).unwrap());
|
|
|
|
|
assert_eq!(
|
|
|
|
|
tl2_u1,
|
|
|
|
|
Timeline::find_for_user_by_name(conn, Some(users[0].id), "another timeline")
|
|
|
|
|
Timeline::find_for_user_by_name(&conn, Some(users[0].id), "another timeline")
|
|
|
|
|
.unwrap()
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
tl1_instance,
|
|
|
|
|
Timeline::find_for_user_by_name(conn, None, "english posts").unwrap()
|
|
|
|
|
Timeline::find_for_user_by_name(&conn, None, "english posts").unwrap()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let tl_u1 = Timeline::list_for_user(conn, Some(users[0].id)).unwrap();
|
|
|
|
|
let tl_u1 = Timeline::list_for_user(&conn, Some(users[0].id)).unwrap();
|
|
|
|
|
assert_eq!(3, tl_u1.len()); // it is not 2 because there is a "Your feed" tl created for each user automatically
|
|
|
|
|
assert!(tl_u1.iter().fold(false, |res, tl| { res || *tl == tl1_u1 }));
|
|
|
|
|
assert!(tl_u1.iter().fold(false, |res, tl| { res || *tl == tl2_u1 }));
|
|
|
|
|
|
|
|
|
|
let tl_instance = Timeline::list_for_user(conn, None).unwrap();
|
|
|
|
|
let tl_instance = Timeline::list_for_user(&conn, None).unwrap();
|
|
|
|
|
assert_eq!(3, tl_instance.len()); // there are also the local and federated feed by default
|
|
|
|
|
assert!(tl_instance
|
|
|
|
|
.iter()
|
|
|
|
|
.fold(false, |res, tl| { res || *tl == tl1_instance }));
|
|
|
|
|
|
|
|
|
|
tl1_u1.name = "My Super TL".to_owned();
|
|
|
|
|
let new_tl1_u2 = tl1_u2.update(conn).unwrap();
|
|
|
|
|
let new_tl1_u2 = tl1_u2.update(&conn).unwrap();
|
|
|
|
|
|
|
|
|
|
let tl_u2 = Timeline::list_for_user(conn, Some(users[1].id)).unwrap();
|
|
|
|
|
let tl_u2 = Timeline::list_for_user(&conn, Some(users[1].id)).unwrap();
|
|
|
|
|
assert_eq!(2, tl_u2.len()); // same here
|
|
|
|
|
assert!(tl_u2
|
|
|
|
|
.iter()
|
|
|
|
@ -328,48 +334,48 @@ mod tests {
|
|
|
|
|
fn test_timeline_creation_error() {
|
|
|
|
|
let conn = &db();
|
|
|
|
|
conn.test_transaction::<_, (), _>(|| {
|
|
|
|
|
let users = userTests::fill_database(conn);
|
|
|
|
|
let users = userTests::fill_database(&conn);
|
|
|
|
|
|
|
|
|
|
assert!(Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"my timeline".to_owned(),
|
|
|
|
|
"invalid keyword".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.is_err());
|
|
|
|
|
assert!(Timeline::new_for_instance(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
"my timeline".to_owned(),
|
|
|
|
|
"invalid keyword".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.is_err());
|
|
|
|
|
|
|
|
|
|
assert!(Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"my timeline".to_owned(),
|
|
|
|
|
"author in non_existant_list".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.is_err());
|
|
|
|
|
assert!(Timeline::new_for_instance(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
"my timeline".to_owned(),
|
|
|
|
|
"lang in dont-exist".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.is_err());
|
|
|
|
|
|
|
|
|
|
List::new(conn, "friends", Some(&users[0]), ListType::User).unwrap();
|
|
|
|
|
List::new(conn, "idk", None, ListType::Blog).unwrap();
|
|
|
|
|
List::new(&conn, "friends", Some(&users[0]), ListType::User).unwrap();
|
|
|
|
|
List::new(&conn, "idk", None, ListType::Blog).unwrap();
|
|
|
|
|
|
|
|
|
|
assert!(Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"my timeline".to_owned(),
|
|
|
|
|
"blog in friends".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.is_err());
|
|
|
|
|
assert!(Timeline::new_for_instance(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
"my timeline".to_owned(),
|
|
|
|
|
"not author in idk".to_owned(),
|
|
|
|
|
)
|
|
|
|
@ -381,13 +387,12 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_simple_match() {
|
|
|
|
|
let r = &rockets();
|
|
|
|
|
let conn = &r.conn;
|
|
|
|
|
let conn = &db();
|
|
|
|
|
conn.test_transaction::<_, (), _>(|| {
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(conn);
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(&conn);
|
|
|
|
|
|
|
|
|
|
let gnu_tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"GNU timeline".to_owned(),
|
|
|
|
|
"license in [AGPL, LGPL, GPL]".to_owned(),
|
|
|
|
@ -395,7 +400,7 @@ mod tests {
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let gnu_post = Post::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPost {
|
|
|
|
|
blog_id: blogs[0].id,
|
|
|
|
|
slug: "slug".to_string(),
|
|
|
|
@ -411,10 +416,10 @@ mod tests {
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(gnu_tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
assert!(gnu_tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
|
|
|
|
|
let non_free_post = Post::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPost {
|
|
|
|
|
blog_id: blogs[0].id,
|
|
|
|
|
slug: "slug2".to_string(),
|
|
|
|
@ -430,7 +435,9 @@ mod tests {
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!gnu_tl.matches(r, &non_free_post, Kind::Original).unwrap());
|
|
|
|
|
assert!(!gnu_tl
|
|
|
|
|
.matches(&conn, &non_free_post, Kind::Original)
|
|
|
|
|
.unwrap());
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
});
|
|
|
|
@ -438,12 +445,11 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_complex_match() {
|
|
|
|
|
let r = &rockets();
|
|
|
|
|
let conn = &r.conn;
|
|
|
|
|
let conn = &db();
|
|
|
|
|
conn.test_transaction::<_, (), _>(|| {
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(conn);
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(&conn);
|
|
|
|
|
Follow::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewFollow {
|
|
|
|
|
follower_id: users[0].id,
|
|
|
|
|
following_id: users[1].id,
|
|
|
|
@ -453,11 +459,11 @@ mod tests {
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let fav_blogs_list =
|
|
|
|
|
List::new(conn, "fav_blogs", Some(&users[0]), ListType::Blog).unwrap();
|
|
|
|
|
fav_blogs_list.add_blogs(conn, &[blogs[0].id]).unwrap();
|
|
|
|
|
List::new(&conn, "fav_blogs", Some(&users[0]), ListType::Blog).unwrap();
|
|
|
|
|
fav_blogs_list.add_blogs(&conn, &[blogs[0].id]).unwrap();
|
|
|
|
|
|
|
|
|
|
let my_tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"My timeline".to_owned(),
|
|
|
|
|
"blog in fav_blogs and not has_cover or local and followed exclude likes"
|
|
|
|
@ -466,7 +472,7 @@ mod tests {
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let post = Post::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPost {
|
|
|
|
|
blog_id: blogs[0].id,
|
|
|
|
|
slug: "about-linux".to_string(),
|
|
|
|
@ -482,10 +488,10 @@ mod tests {
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(my_tl.matches(r, &post, Kind::Original).unwrap()); // matches because of "blog in fav_blogs" (and there is no cover)
|
|
|
|
|
assert!(my_tl.matches(&conn, &post, Kind::Original).unwrap()); // matches because of "blog in fav_blogs" (and there is no cover)
|
|
|
|
|
|
|
|
|
|
let post = Post::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPost {
|
|
|
|
|
blog_id: blogs[1].id,
|
|
|
|
|
slug: "about-linux-2".to_string(),
|
|
|
|
@ -503,7 +509,7 @@ mod tests {
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!my_tl.matches(r, &post, Kind::Like(&users[1])).unwrap());
|
|
|
|
|
assert!(!my_tl.matches(&conn, &post, Kind::Like(&users[1])).unwrap());
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
});
|
|
|
|
@ -511,20 +517,19 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_add_to_all_timelines() {
|
|
|
|
|
let r = &rockets();
|
|
|
|
|
let conn = &r.conn;
|
|
|
|
|
let conn = &db();
|
|
|
|
|
conn.test_transaction::<_, (), _>(|| {
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(conn);
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(&conn);
|
|
|
|
|
|
|
|
|
|
let gnu_tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"GNU timeline".to_owned(),
|
|
|
|
|
"license in [AGPL, LGPL, GPL]".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
let non_gnu_tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"Stallman disapproved timeline".to_owned(),
|
|
|
|
|
"not license in [AGPL, LGPL, GPL]".to_owned(),
|
|
|
|
@ -532,7 +537,7 @@ mod tests {
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let gnu_post = Post::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPost {
|
|
|
|
|
blog_id: blogs[0].id,
|
|
|
|
|
slug: "slug".to_string(),
|
|
|
|
@ -550,7 +555,7 @@ mod tests {
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let non_free_post = Post::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPost {
|
|
|
|
|
blog_id: blogs[0].id,
|
|
|
|
|
slug: "slug2".to_string(),
|
|
|
|
@ -567,13 +572,13 @@ mod tests {
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
Timeline::add_to_all_timelines(r, &gnu_post, Kind::Original).unwrap();
|
|
|
|
|
Timeline::add_to_all_timelines(r, &non_free_post, Kind::Original).unwrap();
|
|
|
|
|
Timeline::add_to_all_timelines(&conn, &gnu_post, Kind::Original).unwrap();
|
|
|
|
|
Timeline::add_to_all_timelines(&conn, &non_free_post, Kind::Original).unwrap();
|
|
|
|
|
|
|
|
|
|
let res = gnu_tl.get_latest(conn, 2).unwrap();
|
|
|
|
|
let res = gnu_tl.get_latest(&conn, 2).unwrap();
|
|
|
|
|
assert_eq!(res.len(), 1);
|
|
|
|
|
assert_eq!(res[0].id, gnu_post.id);
|
|
|
|
|
let res = non_gnu_tl.get_latest(conn, 2).unwrap();
|
|
|
|
|
let res = non_gnu_tl.get_latest(&conn, 2).unwrap();
|
|
|
|
|
assert_eq!(res.len(), 1);
|
|
|
|
|
assert_eq!(res[0].id, non_free_post.id);
|
|
|
|
|
|
|
|
|
@ -583,13 +588,12 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_matches_lists_direct() {
|
|
|
|
|
let r = &rockets();
|
|
|
|
|
let conn = &r.conn;
|
|
|
|
|
let conn = &db();
|
|
|
|
|
conn.test_transaction::<_, (), _>(|| {
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(conn);
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(&conn);
|
|
|
|
|
|
|
|
|
|
let gnu_post = Post::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPost {
|
|
|
|
|
blog_id: blogs[0].id,
|
|
|
|
|
slug: "slug".to_string(),
|
|
|
|
@ -606,61 +610,63 @@ mod tests {
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
gnu_post
|
|
|
|
|
.update_tags(conn, vec![Tag::build_activity("free".to_owned()).unwrap()])
|
|
|
|
|
.update_tags(&conn, vec![Tag::build_activity("free".to_owned()).unwrap()])
|
|
|
|
|
.unwrap();
|
|
|
|
|
PostAuthor::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPostAuthor {
|
|
|
|
|
post_id: gnu_post.id,
|
|
|
|
|
author_id: blogs[0].list_authors(conn).unwrap()[0].id,
|
|
|
|
|
author_id: blogs[0].list_authors(&conn).unwrap()[0].id,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"blog timeline".to_owned(),
|
|
|
|
|
format!("blog in [{}]", blogs[0].fqn),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"blog timeline".to_owned(),
|
|
|
|
|
"blog in [no_one@nowhere]".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"author timeline".to_owned(),
|
|
|
|
|
format!(
|
|
|
|
|
"author in [{}]",
|
|
|
|
|
blogs[0].list_authors(conn).unwrap()[0].fqn
|
|
|
|
|
blogs[0].list_authors(&conn).unwrap()[0].fqn
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"author timeline".to_owned(),
|
|
|
|
|
format!("author in [{}]", users[2].fqn),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
assert!(tl.matches(r, &gnu_post, Kind::Reshare(&users[2])).unwrap());
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Like(&users[2])).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
assert!(tl
|
|
|
|
|
.matches(&conn, &gnu_post, Kind::Reshare(&users[2]))
|
|
|
|
|
.unwrap());
|
|
|
|
|
assert!(!tl.matches(&conn, &gnu_post, Kind::Like(&users[2])).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"author timeline".to_owned(),
|
|
|
|
|
format!(
|
|
|
|
@ -669,48 +675,50 @@ mod tests {
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Reshare(&users[2])).unwrap());
|
|
|
|
|
assert!(tl.matches(r, &gnu_post, Kind::Like(&users[2])).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
assert!(!tl
|
|
|
|
|
.matches(&conn, &gnu_post, Kind::Reshare(&users[2]))
|
|
|
|
|
.unwrap());
|
|
|
|
|
assert!(tl.matches(&conn, &gnu_post, Kind::Like(&users[2])).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"tag timeline".to_owned(),
|
|
|
|
|
"tags in [free]".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"tag timeline".to_owned(),
|
|
|
|
|
"tags in [private]".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"english timeline".to_owned(),
|
|
|
|
|
"lang in [en]".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"franco-italian timeline".to_owned(),
|
|
|
|
|
"lang in [fr, it]".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
});
|
|
|
|
@ -720,12 +728,12 @@ mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_matches_lists_saved() {
|
|
|
|
|
let r = &rockets();
|
|
|
|
|
let conn = &r.conn;
|
|
|
|
|
let conn = &db();
|
|
|
|
|
conn.test_transaction::<_, (), _>(|| {
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(conn);
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(&conn);
|
|
|
|
|
|
|
|
|
|
let gnu_post = Post::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPost {
|
|
|
|
|
blog_id: blogs[0].id,
|
|
|
|
|
slug: "slug".to_string(),
|
|
|
|
@ -741,8 +749,8 @@ mod tests {
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
gnu_post.update_tags(conn, vec![Tag::build_activity("free".to_owned()).unwrap()]).unwrap();
|
|
|
|
|
PostAuthor::insert(conn, NewPostAuthor {post_id: gnu_post.id, author_id: blogs[0].list_authors(conn).unwrap()[0].id}).unwrap();
|
|
|
|
|
gnu_post.update_tags(&conn, vec![Tag::build_activity("free".to_owned()).unwrap()]).unwrap();
|
|
|
|
|
PostAuthor::insert(&conn, NewPostAuthor {post_id: gnu_post.id, author_id: blogs[0].list_authors(&conn).unwrap()[0].id}).unwrap();
|
|
|
|
|
|
|
|
|
|
unimplemented!();
|
|
|
|
|
|
|
|
|
@ -752,13 +760,12 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_matches_keyword() {
|
|
|
|
|
let r = &rockets();
|
|
|
|
|
let conn = &r.conn;
|
|
|
|
|
let conn = &db();
|
|
|
|
|
conn.test_transaction::<_, (), _>(|| {
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(conn);
|
|
|
|
|
let (users, blogs) = blogTests::fill_database(&conn);
|
|
|
|
|
|
|
|
|
|
let gnu_post = Post::insert(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
NewPost {
|
|
|
|
|
blog_id: blogs[0].id,
|
|
|
|
|
slug: "slug".to_string(),
|
|
|
|
@ -776,61 +783,61 @@ mod tests {
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"Linux title".to_owned(),
|
|
|
|
|
"title contains Linux".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"Microsoft title".to_owned(),
|
|
|
|
|
"title contains Microsoft".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"Linux subtitle".to_owned(),
|
|
|
|
|
"subtitle contains Stallman".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"Microsoft subtitle".to_owned(),
|
|
|
|
|
"subtitle contains Nadella".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"Linux content".to_owned(),
|
|
|
|
|
"content contains Linux".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
let tl = Timeline::new_for_user(
|
|
|
|
|
conn,
|
|
|
|
|
&conn,
|
|
|
|
|
users[0].id,
|
|
|
|
|
"Microsoft content".to_owned(),
|
|
|
|
|
"subtitle contains Windows".to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
assert!(!tl.matches(r, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(conn).unwrap();
|
|
|
|
|
assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap());
|
|
|
|
|
tl.delete(&conn).unwrap();
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
});
|
|
|
|
|