aboutsummaryrefslogtreecommitdiff
path: root/tests/tutorial
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tutorial')
-rw-r--r--tests/tutorial/mod.rs54
1 files changed, 44 insertions, 10 deletions
diff --git a/tests/tutorial/mod.rs b/tests/tutorial/mod.rs
index 71cba3d..a9eb76f 100644
--- a/tests/tutorial/mod.rs
+++ b/tests/tutorial/mod.rs
@@ -44,7 +44,7 @@ fn get(url: &str) -> (hyper::StatusCode, String) {
.block_on(get)
}
-pub fn step1(dest: &str) {
+pub fn step1() {
// tosin-admin start-project {dest}
set_current_dir(PROJECT_DIR).unwrap();
set_current_dir("target").unwrap();
@@ -52,16 +52,16 @@ pub fn step1(dest: &str) {
fs::create_dir("tests").unwrap();
}
set_current_dir("tests").unwrap();
- fs::write("Cargo.toml", "[workspace]\nmembers = ['tutorial1']").unwrap();
- if fs::metadata(dest).is_ok() {
- fs::remove_dir_all(dest).unwrap();
+ fs::write("Cargo.toml", "[workspace]\nmembers = ['tutorial']").unwrap();
+ if fs::metadata("tutorial").is_ok() {
+ fs::remove_dir_all("tutorial").unwrap();
}
Command::new(TOSIN_ADMIN)
- .args(&["start-project", dest])
+ .args(&["start-project", "tutorial"])
.status()
.unwrap()
.check();
- set_current_dir(dest).unwrap();
+ set_current_dir("tutorial").unwrap();
assert!(fs::metadata("Cargo.toml").is_ok());
assert!(fs::read_to_string("Cargo.toml").unwrap().contains("tosin = "));
assert!(fs::metadata("src/main.rs").is_ok());
@@ -119,6 +119,7 @@ pub fn urls() -> UrlMap {
fs::write("src/main.rs", r#"
use tosin::Settings;
use tosin::contrib::admin;
+use tosin::db::backend::Connectable;
use tosin::urls::{UrlMap, url_map};
mod polls;
@@ -130,7 +131,7 @@ fn urls() -> UrlMap {
}
}
-fn settings() -> Settings {
+fn settings() -> Settings<impl Connectable> {
Settings {
..Settings::default()
}
@@ -169,7 +170,40 @@ tosin::main!(urls(), settings());
}
}
-pub fn step2(dest: &str) {
- step1(dest);
- todo!();
+pub fn step2() {
+ step1();
+ // update main.rs
+ fs::write("src/main.rs", r#"
+use tosin::Settings;
+use tosin::contrib::admin;
+use tosin::db::backend::Connectable;
+use tosin::urls::{UrlMap, url_map};
+
+mod polls;
+
+fn urls() -> UrlMap {
+ url_map! {
+ "polls" / ..polls::urls(),
+ "admin" / ..admin::site::urls(),
+ }
+}
+
+fn settings() -> Settings<impl Connectable> {
+ Settings {
+ installed_apps: &[
+ &admin::APP,
+ ],
+ ..Settings::default()
+ }
+}
+
+tosin::main!(urls(), settings());
+ "#).unwrap();
+
+ // cargo run migrate
+ Command::new(CARGO)
+ .args(&["run", "migrate"])
+ .status()
+ .unwrap()
+ .check();
}