Skip to content

Commit

Permalink
199: tweak rake task for better results
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevallano committed May 29, 2020
1 parent a2367e6 commit 08a89eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/tmdb_handler.rb
Expand Up @@ -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!(
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions spec/modules/tmdb_handler_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 08a89eb

Please sign in to comment.