Permalink
Browse files

ensure that blank TMDB movie properties cannot erase existing ones

  • Loading branch information...
1 parent f092b55 commit 18d9981945969c20d11c80f6b926a7d649979c38 @mislav committed Apr 15, 2012
Showing with 19 additions and 6 deletions.
  1. +6 −6 app/models/movie.rb
  2. +13 −0 spec/models/movie_spec.rb
View
@@ -109,12 +109,12 @@ def tmdb_movie=(movie)
self.tmdb_url = movie.url
self.imdb_id = movie.imdb_id if movie.imdb_id.present? and self.imdb_id.nil?
- # renamed properties
- set_unless_locked(:title, movie.name)
- set_unless_locked(:original_title, movie.original_name)
- set_unless_locked(:poster_small_url, movie.poster_thumb)
- set_unless_locked(:poster_medium_url, movie.poster_cover)
- set_unless_locked(:plot, movie.synopsis)
+ # renamed properties (from => to)
+ { :name => :title, :original_name => :original_title, :synopsis => :plot,
+ :poster_thumb => :poster_small_url, :poster_cover => :poster_medium_url }.each do |property, db_field|
+ value = movie.send(property)
+ set_unless_locked(db_field, value) if value.present?
+ end
# same name properties
[:year, :runtime, :countries, :directors, :homepage].each do |property|
View
@@ -95,6 +95,19 @@ def collection
movie.runtime.should == 95
movie.directors.should == ['Lone Scherfig']
end
+
+ it "movie plot shouldn't be overwritten with blank one" do
+ movie = Movie.create :tmdb_id => tmdb_id do |m|
+ m['rotten_tomatoes'] = rotten_values
+ end
+
+ movie.ensure_extended_info
+ movie_without_plot = double(:synopsis => '').as_null_object
+
+ expect {
+ movie.tmdb_movie = movie_without_plot
+ }.to_not change(movie, 'plot')
+ end
it "movie with missing info but without a TMDB ID can't get details" do
movie = Movie.create :directors => [] do |m|

0 comments on commit 18d9981

Please sign in to comment.