#[macro_use] extern crate diesel; use tosin::contrib::admin; use tosin::urls::{url_map, UrlMap}; use tosin::Settings; mod polls; fn urls() -> UrlMap { url_map! { "polls" / ..polls::urls(), "admin" / ..admin::site::urls(), } } fn settings() -> Settings { Settings { installed_apps: &[&polls::APP, &admin::APP], ..Settings::default() } } tosin::main!(urls(), settings()); #[cfg(test)] mod test { use super::*; use diesel::prelude::*; #[test] fn test_models() { use polls::models::{choice, question, Choice, Question}; let settings = settings(); let connection = settings.database.connect().unwrap(); // get the list of all questions let all_questions = question::table.load::(&connection).unwrap(); assert!(all_questions.is_empty()); // make a new one let mut q = Question::new( "What's new?".to_string(), chrono::Local::now().naive_local(), ); // save it q.save_mut(&connection); // it's got an id now! assert!(q.id().is_some()); // it's still got all the same fields! assert_eq!(q.question_text(), "What's new?"); // we can change them! q.set_question_text("What's up?"); q.save_mut(&connection); // it should be in the list now, too!! let all_questions = question::table.load::(&connection).unwrap(); assert_eq!(all_questions, vec![q]); } }