Created
July 7, 2017 08:45
-
-
Save pashagray/4840de93f985136380d7c840477d6a68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe '#fetch_from_kinopoisk(kinopoisk_id)' do | |
context 'when movie with such kinopoisk_id exist' do | |
it 'updates movie with fresh data' do | |
stub_kinopoisk_get_film(1) | |
movie = create(:movie, kinopoisk_id: 1) | |
Movie.fetch_from_kinopoisk(movie.kinopoisk_id) | |
expect(Movie.find(movie.id).title_en).to eq('Star Wars: Episode VII - The Force Awakens') | |
end | |
end | |
context 'when movie with such kinopoisk_id does not exist' do | |
it 'creates movie with data and links with genres and countries and creates facts' do | |
stub_kinopoisk_get_film(1) | |
movie = create(:movie, kinopoisk_id: 2) | |
create(:genre_fantasy) | |
create(:genre_fiction) | |
create(:genre_action) | |
create(:country_us) | |
Movie.fetch_from_kinopoisk(1) | |
expect(Movie.last.title_en).to eq('Star Wars: Episode VII - The Force Awakens') | |
expect(Movie.last.genres.map(&:title_en)).to eq(%w(fantasy fiction action)) | |
expect(Movie.last.countries.map(&:title_en)).to eq(%w(USA)) | |
expect(Movie.last.facts.count).to eq(116) | |
expect(Movie.last).not_to eq(movie) | |
end | |
end | |
context 'when movie with such kinopoisk_id does not exist on kinopoisk' do | |
it 'raise MovieNotFoundInKinopoiskDatabaseRrror' do | |
stub_kinopoisk_get_film_nil | |
expect{ Movie.fetch_from_kinopoisk(999_999_999) }.to raise_error(MovieNotFoundInKinopoiskError) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment