hammond-data: Fix PartialEq implementations, add NewPodcast.insert unit test.
This commit is contained in:
parent
da8c3a7827
commit
1625f773c2
@ -95,9 +95,9 @@ impl Index for NewEpisode {
|
|||||||
|
|
||||||
impl PartialEq<EpisodeMinimal> for NewEpisode {
|
impl PartialEq<EpisodeMinimal> for NewEpisode {
|
||||||
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
||||||
(self.title() != other.title()) || (self.uri() != other.uri())
|
(self.title() == other.title()) && (self.uri() == other.uri())
|
||||||
|| (self.duration() != other.duration()) || (self.epoch() != other.epoch())
|
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
|
||||||
|| (self.guid() != other.guid())
|
&& (self.guid() == other.guid())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,9 +167,9 @@ pub(crate) struct NewEpisodeMinimal {
|
|||||||
|
|
||||||
impl PartialEq<EpisodeMinimal> for NewEpisodeMinimal {
|
impl PartialEq<EpisodeMinimal> for NewEpisodeMinimal {
|
||||||
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
fn eq(&self, other: &EpisodeMinimal) -> bool {
|
||||||
(self.title() != other.title()) || (self.uri() != other.uri())
|
(self.title() == other.title()) && (self.uri() == other.uri())
|
||||||
|| (self.duration() != other.duration()) || (self.epoch() != other.epoch())
|
&& (self.duration() == other.duration()) && (self.epoch() == other.epoch())
|
||||||
|| (self.guid() != other.guid())
|
&& (self.guid() == other.guid())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -77,9 +77,10 @@ impl Index for NewPodcast {
|
|||||||
|
|
||||||
impl PartialEq<Podcast> for NewPodcast {
|
impl PartialEq<Podcast> for NewPodcast {
|
||||||
fn eq(&self, other: &Podcast) -> bool {
|
fn eq(&self, other: &Podcast) -> bool {
|
||||||
(self.link() != other.link()) || (self.title() != other.title())
|
(self.link() == other.link()) && (self.title() == other.title())
|
||||||
|| (self.image_uri() != other.image_uri())
|
&& (self.image_uri() == other.image_uri())
|
||||||
|| (self.description() != other.description())
|
&& (self.description() == other.description())
|
||||||
|
&& (self.source_id() == other.source_id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,6 +154,7 @@ mod tests {
|
|||||||
|
|
||||||
use rss::Channel;
|
use rss::Channel;
|
||||||
|
|
||||||
|
use database::truncate_db;
|
||||||
use models::NewPodcastBuilder;
|
use models::NewPodcastBuilder;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@ -286,4 +288,38 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(pd, expected);
|
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 Intercept’s fearless reporting and incisive \
|
||||||
|
commentary—Jeremy Scahill, Glenn Greenwald, Betsy Reed and others—discuss \
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user