-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
754cab7
commit 863ee6a
Showing
4 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe TmdbHandler, type: :module do | ||
let(:movie) { create(:movie_in_tmdb) } | ||
let(:tmdb_id) { movie.tmdb_id } | ||
subject { TmdbHandler.tmdb_handler_update_movie(tmdb_id) } | ||
|
||
context 'with a valid movie' do | ||
it 'returns true' do | ||
VCR.use_cassette('tmdb_handler_update_movie_with_a_valid_movie', record: :new_episodes) do | ||
expect(subject).to eq(true) | ||
end | ||
end | ||
|
||
it 'updates the movie' do | ||
VCR.use_cassette('tmdb_handler_update_movie_with_a_valid_movie', record: :new_episodes) do | ||
expect{ subject }.to change{ movie.reload.updated_at } | ||
end | ||
end | ||
end | ||
|
||
context 'when movie is not found in db' do | ||
let(:tmdb_id) { 'wrong' } | ||
it { is_expected.to be_nil } | ||
it { expect{subject}.not_to change{ movie.reload.updated_at } } | ||
end | ||
|
||
context 'when no movie found from api response' do | ||
before { movie.update(tmdb_id: 'wrong')} | ||
it 'returns nil' do | ||
VCR.use_cassette('tmdb_handler_update_movie_with_an_invalid_movie', record: :new_episodes) do | ||
expect(subject).to be_nil | ||
end | ||
end | ||
|
||
it 'does not update the movie' do | ||
VCR.use_cassette('tmdb_handler_update_movie_with_an_invalid_movie', record: :new_episodes) do | ||
expect{ subject }.not_to change{ movie.reload.updated_at } | ||
end | ||
end | ||
end | ||
|
||
context 'when the title does not match' do | ||
before { movie.update(title: 'Fargowrong') } | ||
it 'returns nil' do | ||
VCR.use_cassette('tmdb_handler_update_movie_with_wrong_title', record: :new_episodes) do | ||
expect(subject).to be_nil | ||
end | ||
end | ||
|
||
it 'does not update the movie' do | ||
VCR.use_cassette('tmdb_handler_update_movie_with_wrong_title', record: :new_episodes) do | ||
expect{ subject }.not_to change{ movie.reload.updated_at } | ||
end | ||
end | ||
end | ||
|
||
context 'with outdated info' do | ||
let(:wrong_mpaa_rating) { 'G' } | ||
let(:correct_mpaa_rating) { 'R' } | ||
before { movie.update(mpaa_rating: wrong_mpaa_rating) } | ||
it 'updates movie with latest tmdb info' do | ||
VCR.use_cassette('tmdb_handler_update_movie_with_outdated_info', record: :new_episodes) do | ||
subject | ||
expect(movie.reload.mpaa_rating).to eq(correct_mpaa_rating) | ||
end | ||
end | ||
end | ||
|
||
context 'when the movie fails to save' do | ||
let(:dupe_movie) { build(:movie, tmdb_id: movie.tmdb_id) } | ||
before { dupe_movie.save(validate: false) } | ||
|
||
it 'returns nil' do | ||
VCR.use_cassette('tmdb_handler_update_movie_with_a_valid_movie', record: :new_episodes) do | ||
expect(subject).to be_nil | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
VCR.configure do |config| | ||
config.cassette_library_dir = "spec/vcr_cassettes" | ||
config.hook_into :webmock | ||
config.allow_http_connections_when_no_cassette = true | ||
config.allow_http_connections_when_no_cassette = false | ||
config.ignore_localhost = true | ||
end | ||
end |