test(gpodder_sqlite): start device tests
This commit is contained in:
parent
22016fe0e9
commit
73988d6264
6 changed files with 51 additions and 7 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use diesel::{alias, dsl::not, prelude::*};
|
||||
use diesel::{alias, dsl::not, prelude::*, sqlite::Sqlite};
|
||||
use gpodder::AuthErr;
|
||||
|
||||
use super::SqliteRepository;
|
||||
|
|
@ -70,6 +70,8 @@ impl gpodder::DeviceRepository for SqliteRepository {
|
|||
patch: gpodder::DevicePatch,
|
||||
) -> Result<(), gpodder::AuthErr> {
|
||||
(|| {
|
||||
let conn = &mut self.pool.get()?;
|
||||
|
||||
if let Some(mut device) = devices::table
|
||||
.select(Device::as_select())
|
||||
.filter(
|
||||
|
|
@ -77,7 +79,7 @@ impl gpodder::DeviceRepository for SqliteRepository {
|
|||
.eq(user.id)
|
||||
.and(devices::device_id.eq(device_id)),
|
||||
)
|
||||
.get_result(&mut self.pool.get()?)
|
||||
.get_result(conn)
|
||||
.optional()?
|
||||
{
|
||||
if let Some(caption) = patch.caption {
|
||||
|
|
@ -93,7 +95,7 @@ impl gpodder::DeviceRepository for SqliteRepository {
|
|||
devices::caption.eq(&device.caption),
|
||||
devices::type_.eq(&device.type_),
|
||||
))
|
||||
.execute(&mut self.pool.get()?)?;
|
||||
.execute(conn)?;
|
||||
} else {
|
||||
let device = NewDevice {
|
||||
device_id: device_id.to_string(),
|
||||
|
|
@ -104,7 +106,7 @@ impl gpodder::DeviceRepository for SqliteRepository {
|
|||
|
||||
diesel::insert_into(devices::table)
|
||||
.values(device)
|
||||
.execute(&mut self.pool.get()?)?;
|
||||
.execute(conn)?;
|
||||
}
|
||||
|
||||
Ok::<_, DbError>(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue