aboutsummaryrefslogtreecommitdiff
path: root/tests/tutorial
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-06-28 17:02:45 -0600
committerMelody Horn <melody@boringcactus.com>2021-06-28 17:02:45 -0600
commit2e3930b4c7c26e91c1341d7d04d33d91758f8009 (patch)
treeeabac3a8e760e2dc91a548b337f5f2ffe51a6285 /tests/tutorial
parent8852f0b7090c612f1d04a60becb55bbe56441eda (diff)
downloadtosin-2e3930b4c7c26e91c1341d7d04d33d91758f8009.tar.gz
tosin-2e3930b4c7c26e91c1341d7d04d33d91758f8009.zip
work properly on windows too
Diffstat (limited to 'tests/tutorial')
-rw-r--r--tests/tutorial/mod.rs86
1 files changed, 64 insertions, 22 deletions
diff --git a/tests/tutorial/mod.rs b/tests/tutorial/mod.rs
index 25f251b..8a602a3 100644
--- a/tests/tutorial/mod.rs
+++ b/tests/tutorial/mod.rs
@@ -63,9 +63,13 @@ pub fn step1() {
.check();
set_current_dir("tutorial").unwrap();
assert!(fs::metadata("Cargo.toml").is_ok());
- assert!(fs::read_to_string("Cargo.toml").unwrap().contains("tosin = "));
+ assert!(fs::read_to_string("Cargo.toml")
+ .unwrap()
+ .contains("tosin = "));
assert!(fs::metadata("src/main.rs").is_ok());
- assert!(fs::read_to_string("src/main.rs").unwrap().contains("tosin::main!"));
+ assert!(fs::read_to_string("src/main.rs")
+ .unwrap()
+ .contains("tosin::main!"));
// cargo run run-server
let port = thread_rng().gen_range(8081u16..9000u16);
@@ -90,20 +94,28 @@ pub fn step1() {
// tosin-admin start-app polls
Command::new(TOSIN_ADMIN)
.args(&["start-app", "polls"])
- .status().unwrap().check();
+ .status()
+ .unwrap()
+ .check();
assert!(fs::metadata("src/polls/mod.rs").is_ok());
// write views.rs
- fs::write("src/polls/views.rs", r#"
+ fs::write(
+ "src/polls/views.rs",
+ r#"
use tosin::http::{Reply, Response};
pub fn index() -> Response {
"Hello, world. You're at the polls index.".into_response()
}
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// write urls.rs
- fs::write("src/polls/urls.rs", r#"
+ fs::write(
+ "src/polls/urls.rs",
+ r#"
use tosin::urls::{UrlMap, url_map};
use super::views;
@@ -113,10 +125,14 @@ pub fn urls() -> UrlMap {
=> views::index, // TODO name: "index"
}
}
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// update main.rs
- fs::write("src/main.rs", r#"
+ fs::write(
+ "src/main.rs",
+ r#"
#[macro_use] extern crate diesel;
use tosin::Settings;
@@ -140,7 +156,9 @@ fn settings() -> Settings<impl Connectable> {
}
tosin::main!(urls(), settings());
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// poke that new route
let port = thread_rng().gen_range(8081u16..9000u16);
@@ -163,7 +181,14 @@ tosin::main!(urls(), settings());
// vibe check
let test_tutorial1 = Path::new("src");
let example_tutorial1 = Path::new(PROJECT_DIR).join("examples/tutorial01");
- for file in &["main.rs", "polls/mod.rs", "polls/migrations/mod.rs", "polls/models.rs", "polls/urls.rs", "polls/views.rs"] {
+ for file in &[
+ "main.rs",
+ "polls/mod.rs",
+ "polls/migrations/mod.rs",
+ "polls/models.rs",
+ "polls/urls.rs",
+ "polls/views.rs",
+ ] {
let test_path = test_tutorial1.join(file);
let test_file = fs::read_to_string(test_path).unwrap();
let example_path = example_tutorial1.join(file);
@@ -175,7 +200,9 @@ tosin::main!(urls(), settings());
pub fn step2() {
step1();
// update main.rs
- fs::write("src/main.rs", r#"
+ fs::write(
+ "src/main.rs",
+ r#"
#[macro_use] extern crate diesel;
use tosin::Settings;
@@ -202,7 +229,9 @@ fn settings() -> Settings<impl Connectable> {
}
tosin::main!(urls(), settings());
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// cargo run migrate
Command::new(CARGO)
@@ -210,9 +239,11 @@ tosin::main!(urls(), settings());
.status()
.unwrap()
.check();
-
+
// update Cargo.toml
- fs::write("Cargo.toml", r#"
+ fs::write(
+ "Cargo.toml",
+ r#"
[package]
name = "tutorial"
version = "0.1.0"
@@ -221,13 +252,18 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+chrono = "0.4"
diesel = { version = "1.4.4", features = ["sqlite"] }
time = "0.2.27"
-tosin = { path = "/home/cactus/Documents/tosin" }
- "#).unwrap();
-
+tosin = { path = "../../.." }
+ "#,
+ )
+ .unwrap();
+
// update polls/models.rs
- fs::write("src/polls/models.rs", r#"
+ fs::write(
+ "src/polls/models.rs",
+ r#"
use tosin::db::models::{Model, Id, gather};
#[derive(Model)]
@@ -236,7 +272,7 @@ pub struct Question {
#[model(max_length=200)]
question_text: String,
/// date published
- pub_date: time::PrimitiveDateTime,
+ pub_date: chrono::NaiveDateTime,
}
#[derive(Model)]
@@ -251,10 +287,14 @@ pub struct Choice {
}
gather!();
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// update main.rs
- fs::write("src/main.rs", r#"
+ fs::write(
+ "src/main.rs",
+ r#"
#[macro_use] extern crate diesel;
use tosin::Settings;
@@ -282,7 +322,9 @@ fn settings() -> Settings<impl Connectable> {
}
tosin::main!(urls(), settings());
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// cargo run make-migrations
Command::new(CARGO)