aboutsummaryrefslogtreecommitdiff
path: root/tests/tutorial
diff options
context:
space:
mode:
authorMelody Horn / boringcactus <melody@boringcactus.com>2021-06-16 12:36:47 -0600
committerMelody Horn / boringcactus <melody@boringcactus.com>2021-06-16 12:36:47 -0600
commit685b47247aad71468f190c42929ca6f0dce843fa (patch)
tree7adf64a4c00b9ca8893fab26367ec01a30e24ad9 /tests/tutorial
parent92bf14bb7cc0c10f67a9a67e7512138c15db6ec0 (diff)
downloadtosin-685b47247aad71468f190c42929ca6f0dce843fa.tar.gz
tosin-685b47247aad71468f190c42929ca6f0dce843fa.zip
make database backends generic
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();
}