From 08a89eb87162b8c9112121144bf01b4584551c0e Mon Sep 17 00:00:00 2001 From: mike vallano Date: Thu, 28 May 2020 19:23:20 -0500 Subject: [PATCH] 199: tweak rake task for better results --- lib/tmdb_handler.rb | 7 +++---- spec/modules/tmdb_handler_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/tmdb_handler.rb b/lib/tmdb_handler.rb index 969614e7..d677869d 100644 --- a/lib/tmdb_handler.rb +++ b/lib/tmdb_handler.rb @@ -92,13 +92,12 @@ def self.tmdb_handler_update_movie(movie) tmdb_id = movie.tmdb_id movie_url = "#{BASE_URL}/movie/#{tmdb_id}?api_key=#{ENV['tmdb_api_key']}&append_to_response=trailers,credits,similar,releases" api_result = HTTParty.get(movie_url).deep_symbolize_keys rescue nil - raise TmdbHandlerError.new("API request failed for tmdb_id: #{tmdb_id}") unless api_result && api_result[:id].to_s == tmdb_id.to_s + raise TmdbHandlerError.new("API request failed for movie: #{movie.title}") unless api_result && api_result[:id].to_s == tmdb_id.to_s updated_data = MovieMore.tmdb_info(api_result) if movie.title != updated_data.title - puts "Movie title doesn't match. Movie not updated. tmdb_id: #{tmdb_id}. Current title: #{movie.title}. Title in TMDB: #{updated_data.title}" - return + puts "Movie title doesn't match. tmdb_id: #{tmdb_id}. Current title: #{movie.title}. Title in TMDB: #{updated_data.title}" end movie.update!( @@ -120,7 +119,7 @@ def self.tmdb_handler_update_movie(movie) updated_at: Time.current ) rescue ActiveRecord::RecordInvalid => error - raise TmdbHandlerError.new(error.message) + raise TmdbHandlerError.new("#{movie.title} failed update. #{error.message}") end def tmdb_handler_actor_more(actor_id) diff --git a/spec/modules/tmdb_handler_spec.rb b/spec/modules/tmdb_handler_spec.rb index 14493ae6..db28220c 100644 --- a/spec/modules/tmdb_handler_spec.rb +++ b/spec/modules/tmdb_handler_spec.rb @@ -36,9 +36,9 @@ end end - it 'does not update the movie' do + it 'still updates 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 } + expect{ subject }.to change{ movie.reload.updated_at } end end end