Fix #3822: Move favorites (while deleting) fails if user has also favorited destination

This commit is contained in:
evazion
2018-08-19 00:54:17 -05:00
parent eaef616a01
commit c504ad555d
2 changed files with 10 additions and 4 deletions

View File

@@ -966,6 +966,13 @@ class Post < ApplicationRecord
clean_fav_string! if clean_fav_string?
end
def add_favorite(user)
add_favorite!(user)
true
rescue Favorite::Error
false
end
def add_favorite!(user)
Favorite.add(post: self, user: user)
vote!("up", user) if user.is_voter?
@@ -1295,7 +1302,7 @@ class Post < ApplicationRecord
transaction do
favorites.each do |fav|
remove_favorite!(fav.user)
parent.add_favorite!(fav.user)
parent.add_favorite(fav.user)
end
end