hammond-data: Fix PartialEq implementations, add NewPodcast.insert unit test.

This commit is contained in:
Jordan Petridis 2018-01-21 08:39:50 +02:00
parent da8c3a7827
commit 1625f773c2
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 45 additions and 9 deletions

View File

@ -95,9 +95,9 @@ impl Index for NewEpisode {
impl PartialEq<EpisodeMinimal> for NewEpisode {
fn eq(&self, other: &EpisodeMinimal) -> bool {
(self.title() != other.title()) || (self.uri() != other.uri())
|| (self.duration() != other.duration()) || (self.epoch() != other.epoch())
|| (self.guid() != other.guid())
(self.title() == other.title()) && (self.uri() == other.uri())
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
&& (self.guid() == other.guid())
}
}
@ -167,9 +167,9 @@ pub(crate) struct NewEpisodeMinimal {
impl PartialEq<EpisodeMinimal> for NewEpisodeMinimal {
fn eq(&self, other: &EpisodeMinimal) -> bool {
(self.title() != other.title()) || (self.uri() != other.uri())
|| (self.duration() != other.duration()) || (self.epoch() != other.epoch())
|| (self.guid() != other.guid())
(self.title() == other.title()) && (self.uri() == other.uri())
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
&& (self.guid() == other.guid())
}
}

View File

@ -77,9 +77,10 @@ impl Index for NewPodcast {
impl PartialEq<Podcast> for NewPodcast {
fn eq(&self, other: &Podcast) -> bool {
(self.link() != other.link()) || (self.title() != other.title())
|| (self.image_uri() != other.image_uri())
|| (self.description() != other.description())
(self.link() == other.link()) && (self.title() == other.title())
&& (self.image_uri() == other.image_uri())
&& (self.description() == other.description())
&& (self.source_id() == other.source_id())
}
}
@ -153,6 +154,7 @@ mod tests {
use rss::Channel;
use database::truncate_db;
use models::NewPodcastBuilder;
use std::fs::File;
@ -286,4 +288,38 @@ mod tests {
assert_eq!(pd, expected);
}
#[test]
// This maybe could be a doc test on insert.
fn test_new_podcast_insert() {
truncate_db().unwrap();
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
let channel = Channel::read_from(BufReader::new(file)).unwrap();
let npd = NewPodcast::new(&channel, 0);
npd.insert().unwrap();
let pd = dbqueries::get_podcast_from_source_id(0).unwrap();
let descr = "The people behind The Intercepts fearless reporting and incisive \
commentaryJeremy Scahill, Glenn Greenwald, Betsy Reed and othersdiscuss \
the crucial issues of our time: national security, civil liberties, foreign \
policy, and criminal justice. Plus interviews with artists, thinkers, and \
newsmakers who challenge our preconceptions about the world we live in.";
let expected = NewPodcastBuilder::default()
.title("Intercepted with Jeremy Scahill")
.link("https://theintercept.com/podcasts")
.description(descr)
.image_uri(Some(String::from(
"http://static.megaphone.fm/podcasts/d5735a50-d904-11e6-8532-73c7de466ea6/image/\
uploads_2F1484252190700-qhn5krasklbce3dh-a797539282700ea0298a3a26f7e49b0b_\
2FIntercepted_COVER%2B_281_29.png")
))
.build()
.unwrap();
assert_eq!(npd, pd);
assert_eq!(&expected, &pd);
assert_eq!(&expected, &npd);
}
}