aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml3
-rw-r--r--src/main.rs20
2 files changed, 20 insertions, 3 deletions
diff --git a/Cargo.toml b/Cargo.toml
index e67b75b..df40309 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,3 +21,6 @@ serde_json = "1.0"
version = "0.3.15"
default-features = false
features = ["json"]
+
+[dev-dependencies]
+victoria-dom = "0.1"
diff --git a/src/main.rs b/src/main.rs
index 7d75c61..cbf61ac 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -43,17 +43,31 @@ fn main() {
#[cfg(test)]
mod test {
+ extern crate victoria_dom;
+
mod test_helpers;
+ use self::victoria_dom::DOM;
use super::build_rocket;
+ use super::models::Post;
+ use super::utils;
use rocket::local::Client;
- use rocket::http::Status;
+ use rocket::http::{Accept, Status};
#[test]
- fn get_landing_page() {
+ fn landing_page_shows_published_posts() {
let pool = test_helpers::init_test_db_pool();
+ let conn = utils::DbConn(pool.get().unwrap());
let client = Client::new(build_rocket(pool)).expect("Rocket not built!");
- let response = client.get("/").dispatch();
+ let mut response = client
+ .get("/")
+ .header(Accept::HTML)
+ .dispatch();
assert_eq!(response.status(), Status::Ok);
+
+ let dom = DOM::new(&response.body_string().unwrap());
+ let displayed_posts = dom.at("body").unwrap().childs(Some(".post-teaser")).iter().count();
+ let posts = Post::get_all(&conn);
+ assert_eq!(displayed_posts, posts.len());
}
}