2018-11-01 22:23:38 +01:00
|
|
|
extern crate diesel;
|
|
|
|
#[macro_use] extern crate diesel_migrations;
|
|
|
|
|
|
|
|
extern crate plume_models;
|
|
|
|
|
|
|
|
use diesel::Connection;
|
|
|
|
use plume_models::{
|
2018-11-07 15:50:24 +01:00
|
|
|
DATABASE_URL,
|
2018-11-01 22:23:38 +01:00
|
|
|
Connection as Conn,
|
|
|
|
instance::*,
|
|
|
|
safe_string::SafeString,
|
|
|
|
};
|
|
|
|
|
2018-11-07 15:50:24 +01:00
|
|
|
#[cfg(feature = "sqlite")]
|
2018-11-01 22:23:38 +01:00
|
|
|
embed_migrations!("../migrations/sqlite");
|
|
|
|
|
2018-11-07 15:50:24 +01:00
|
|
|
#[cfg(feature = "postgres")]
|
|
|
|
embed_migrations!("../migrations/postgres");
|
|
|
|
|
2018-11-01 22:23:38 +01:00
|
|
|
fn db() -> Conn {
|
2018-11-07 15:50:24 +01:00
|
|
|
let conn = Conn::establish(&*DATABASE_URL.as_str()).expect("Couldn't connect to the database");
|
2018-11-01 22:23:38 +01:00
|
|
|
embedded_migrations::run(&conn).expect("Couldn't run migrations");
|
|
|
|
conn
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn instance_insert() {
|
|
|
|
let conn = &db();
|
2018-11-07 15:50:24 +01:00
|
|
|
conn.test_transaction::<_, (), _>(|| {
|
|
|
|
Instance::insert(conn, NewInstance {
|
|
|
|
default_license: "WTFPL".to_string(),
|
|
|
|
local: true,
|
|
|
|
long_description: SafeString::new("This is my instance."),
|
|
|
|
long_description_html: "<p>This is my instance</p>".to_string(),
|
|
|
|
short_description: SafeString::new("My instance."),
|
|
|
|
short_description_html: "<p>My instance</p>".to_string(),
|
|
|
|
name: "My instance".to_string(),
|
|
|
|
open_registrations: true,
|
|
|
|
public_domain: "plu.me".to_string(),
|
|
|
|
});
|
|
|
|
let inst = Instance::get_local(conn);
|
|
|
|
assert!(inst.is_some());
|
|
|
|
let inst = inst.unwrap();
|
|
|
|
assert_eq!(inst.name, "My instance".to_string());
|
|
|
|
Ok(())
|
2018-11-01 22:23:38 +01:00
|
|
|
});
|
|
|
|
}
|