rss Channel guarantes that some fields exist and dont need to be Option<foo>.

This commit is contained in:
Jordan Petridis 2017-09-19 08:33:14 +03:00
parent ffda7c6fc8
commit fe2d8c8b52
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
4 changed files with 16 additions and 22 deletions

View File

@ -22,8 +22,8 @@ CREATE TABLE `podcast` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
`title` TEXT NOT NULL, `title` TEXT NOT NULL,
`uri` TEXT UNIQUE NOT NULL, `uri` TEXT UNIQUE NOT NULL,
`link` TEXT, `link` TEXT NOT NULL,
`description` TEXT, `description` TEXT NOT NULL,
`image_uri` TEXT, `image_uri` TEXT,
`source_id` INTEGER NOT NULL `source_id` INTEGER NOT NULL
); );

View File

@ -31,8 +31,8 @@ pub struct Podcast {
id: i32, id: i32,
title: String, title: String,
uri: String, uri: String,
link: Option<String>, link: String,
description: Option<String>, description: String,
image_uri: Option<String>, image_uri: Option<String>,
source_id: i32, source_id: i32,
} }
@ -77,8 +77,8 @@ pub struct NewEpisode<'a> {
pub struct NewPodcast { pub struct NewPodcast {
pub title: String, pub title: String,
pub uri: String, pub uri: String,
pub link: Option<String>, pub link: String,
pub description: Option<String>, pub description: String,
pub image_uri: Option<String>, pub image_uri: Option<String>,
} }

View File

@ -5,9 +5,9 @@ use errors::*;
pub fn parse_podcast(chan: &Channel, uri: &str) -> Result<models::NewPodcast> { pub fn parse_podcast(chan: &Channel, uri: &str) -> Result<models::NewPodcast> {
let title = chan.title().to_owned(); let title = chan.title().to_owned();
let link = chan.link().to_owned();
let link = Some(chan.link().to_owned()); let description = chan.description().to_owned();
let description = Some(chan.description().to_owned());
// let image_uri = match chan.image() { // let image_uri = match chan.image() {
// Some(foo) => Some(foo.url().to_owned()), // Some(foo) => Some(foo.url().to_owned()),
@ -86,11 +86,8 @@ mod tests {
pd.uri, pd.uri,
"https://feeds.feedburner.com/InterceptedWithJeremyScahill".to_string() "https://feeds.feedburner.com/InterceptedWithJeremyScahill".to_string()
); );
assert_eq!( assert_eq!(pd.link, "https://theintercept.com/podcasts".to_string());
pd.link, assert_eq!(pd.description, descr.to_string());
Some("https://theintercept.com/podcasts".to_string())
);
assert_eq!(pd.description, Some(descr.to_string()));
assert_eq!(pd.image_uri, None); assert_eq!(pd.image_uri, None);
@ -104,11 +101,8 @@ mod tests {
let pd = parse_podcast(&channel, uri).unwrap(); let pd = parse_podcast(&channel, uri).unwrap();
assert_eq!(pd.title, "LINUX Unplugged Podcast".to_string()); assert_eq!(pd.title, "LINUX Unplugged Podcast".to_string());
assert_eq!( assert_eq!(pd.link, "http://www.jupiterbroadcasting.com/".to_string());
pd.link, assert_eq!(pd.description, descr.to_string());
Some("http://www.jupiterbroadcasting.com/".to_string())
);
assert_eq!(pd.description, Some(descr.to_string()));
assert_eq!( assert_eq!(
pd.image_uri, pd.image_uri,
Some( Some(
@ -132,9 +126,9 @@ mod tests {
); );
assert_eq!( assert_eq!(
pd.link, pd.link,
Some("https://www.propublica.org/feeds/54Ghome".to_string()) "https://www.propublica.org/feeds/54Ghome".to_string()
); );
assert_eq!(pd.description, Some(descr.to_string())); assert_eq!(pd.description, descr.to_string());
assert_eq!( assert_eq!(
pd.image_uri, pd.image_uri,
Some( Some(

View File

@ -18,8 +18,8 @@ table! {
id -> Integer, id -> Integer,
title -> Text, title -> Text,
uri -> Text, uri -> Text,
link -> Nullable<Text>, link -> Text,
description -> Nullable<Text>, description -> Text,
image_uri -> Nullable<Text>, image_uri -> Nullable<Text>,
source_id -> Integer, source_id -> Integer,
} }