favoritescontroller#destroy should work even if the post doesn't exist, remove from favorites on expunge (fixes #3222)

This commit is contained in:
r888888888
2017-07-19 13:22:24 -07:00
parent 5d013f9c88
commit d48ed95191
7 changed files with 50 additions and 21 deletions

View File

@@ -982,7 +982,7 @@ class Post < ApplicationRecord
end
def add_favorite!(user)
Favorite.add(self, user)
Favorite.add(post: self, user: user)
vote!("up", user) if user.is_voter?
rescue PostVote::Error
end
@@ -992,7 +992,7 @@ class Post < ApplicationRecord
end
def remove_favorite!(user)
Favorite.remove(self, user)
Favorite.remove(post: self, user: user)
unvote!(user) if user.is_voter?
rescue PostVote::Error
end
@@ -1022,6 +1022,10 @@ class Post < ApplicationRecord
end
end
def remove_from_favorites
Favorite.destroy_all(post_id: self.id)
end
def remove_from_fav_groups
FavoriteGroup.for_post(id).find_each do |group|
group.remove!(self)
@@ -1383,6 +1387,7 @@ class Post < ApplicationRecord
decrement_tag_post_counts
remove_from_all_pools
remove_from_fav_groups
remove_from_favorites
destroy
update_parent_on_destroy
end