aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-08-02 20:06:47 +0200
committerHarald Eilertsen <haraldei@anduin.net>2018-08-02 20:06:47 +0200
commitb88fe0e8473010db45d81840251a44ca96f0f046 (patch)
treef03c0c8b11de0cc1e14f4faebdbf8d36df1d9ee8
parent992e8454bbdcb2c6c6b7c7bb3f052ebc262d05b9 (diff)
downloadrocket-blog-b88fe0e8473010db45d81840251a44ca96f0f046.tar.gz
rocket-blog-b88fe0e8473010db45d81840251a44ca96f0f046.tar.bz2
rocket-blog-b88fe0e8473010db45d81840251a44ca96f0f046.zip
Flesh out first test some more.HEADmaster
-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());
}
}