Skip to content

Commit

Permalink
Refactor to improve it a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevallano committed Dec 1, 2019
1 parent e352b27 commit 9a1ba63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/user.rb
Expand Up @@ -62,8 +62,8 @@ def all_listings
end

def lists_except_movie(movie = nil)
if movie.present? && existing_movie = Movie.find_by(tmdb_id: movie.tmdb_id)
(all_lists - existing_movie.lists.by_user(self))
if movie.present? && movie.in_db
(all_lists - movie.lists.by_user(self))
.sort_by { |list| list.name.downcase }
else
all_lists_by_name
Expand Down
7 changes: 6 additions & 1 deletion spec/models/user_spec.rb
Expand Up @@ -57,6 +57,11 @@
expect(user.lists_except_movie(movie)).to include(list2)
end

it "responds to lists_except_movie" do
list2
expect(user.lists_except_movie).to match_array([list, list2])
end

it "responds to all_movies" do
expect(user).to respond_to(:all_movies)
end
Expand Down Expand Up @@ -105,4 +110,4 @@
end
end

end #final
end #final

0 comments on commit 9a1ba63

Please sign in to comment.