Fix #4462: "You have already favorited this post" on upload.
Make adding the fav:self metatag ignore all errors, including when the post was already favorited before editing the post.
This commit is contained in:
@@ -625,10 +625,10 @@ class Post < ApplicationRecord
|
|||||||
add_pool!(pool) if pool
|
add_pool!(pool) if pool
|
||||||
|
|
||||||
when /^fav:(.+)$/i
|
when /^fav:(.+)$/i
|
||||||
add_favorite!(CurrentUser.user)
|
add_favorite(CurrentUser.user)
|
||||||
|
|
||||||
when /^-fav:(.+)$/i
|
when /^-fav:(.+)$/i
|
||||||
remove_favorite!(CurrentUser.user)
|
remove_favorite(CurrentUser.user)
|
||||||
|
|
||||||
when /^(up|down)vote:(.+)$/i
|
when /^(up|down)vote:(.+)$/i
|
||||||
vote!($1)
|
vote!($1)
|
||||||
@@ -792,6 +792,13 @@ class Post < ApplicationRecord
|
|||||||
rescue PostVote::Error
|
rescue PostVote::Error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_favorite(user)
|
||||||
|
remove_favorite!(user)
|
||||||
|
true
|
||||||
|
rescue Favorite::Error
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
# users who favorited this post, ordered by users who favorited it first
|
# users who favorited this post, ordered by users who favorited it first
|
||||||
def favorited_users
|
def favorited_users
|
||||||
favorited_user_ids = fav_string.scan(/\d+/).map(&:to_i)
|
favorited_user_ids = fav_string.scan(/\d+/).map(&:to_i)
|
||||||
|
|||||||
@@ -954,6 +954,14 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
@post.update(tag_string: "aaa -fav:self")
|
@post.update(tag_string: "aaa -fav:self")
|
||||||
assert_equal("", @post.fav_string)
|
assert_equal("", @post.fav_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "not fail when the fav: metatag is used twice" do
|
||||||
|
@post.update(tag_string: "aaa fav:self fav:me")
|
||||||
|
assert_equal("fav:#{@user.id}", @post.fav_string)
|
||||||
|
|
||||||
|
@post.update(tag_string: "aaa -fav:self -fav:me")
|
||||||
|
assert_equal("", @post.fav_string)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "for a child" do
|
context "for a child" do
|
||||||
|
|||||||
Reference in New Issue
Block a user