mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 18:03:38 +08:00
FIX: problems with choosing favorite badges (#13731)
This commit is contained in:
parent
4ce58fbf0b
commit
5cd447695e
|
@ -109,10 +109,13 @@ class UserBadgesController < ApplicationController
|
|||
return render json: failed_json, status: 400
|
||||
end
|
||||
|
||||
new_is_favorite_value = !user_badge.is_favorite
|
||||
UserBadge
|
||||
.where(user_id: user_badge.user_id, badge_id: user_badge.badge_id)
|
||||
.update(is_favorite: !user_badge.is_favorite)
|
||||
.update_all(is_favorite: new_is_favorite_value)
|
||||
UserBadge.update_featured_ranks!(user_badge.user_id)
|
||||
|
||||
user_badge.is_favorite = new_is_favorite_value
|
||||
render_serialized(user_badge, DetailedUserBadgeSerializer, root: :user_badge)
|
||||
end
|
||||
|
||||
|
|
|
@ -294,20 +294,26 @@ describe UserBadgesController do
|
|||
it "favorites a badge" do
|
||||
sign_in(user)
|
||||
put "/user_badges/#{user_badge.id}/toggle_favorite.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["user_badge"]["is_favorite"]).to eq(true)
|
||||
|
||||
user_badge = UserBadge.find_by(user: user, badge: badge)
|
||||
expect(user_badge.is_favorite).to be true
|
||||
expect(user_badge.is_favorite).to eq(true)
|
||||
end
|
||||
|
||||
it "unfavorites a badge" do
|
||||
sign_in(user)
|
||||
user_badge.toggle!(:is_favorite)
|
||||
put "/user_badges/#{user_badge.id}/toggle_favorite.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["user_badge"]["is_favorite"]).to eq(false)
|
||||
|
||||
user_badge = UserBadge.find_by(user: user, badge: badge)
|
||||
expect(user_badge.is_favorite).to be false
|
||||
expect(user_badge.is_favorite).to eq(false)
|
||||
end
|
||||
|
||||
it "works with multiple grants" do
|
||||
|
@ -323,16 +329,22 @@ describe UserBadgesController do
|
|||
|
||||
put "/user_badges/#{user_badge.id}/toggle_favorite.json"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["user_badge"]["is_favorite"]).to eq(false)
|
||||
expect(user_badge.reload.is_favorite).to eq(false)
|
||||
expect(user_badge2.reload.is_favorite).to eq(false)
|
||||
|
||||
put "/user_badges/#{user_badge.id}/toggle_favorite.json"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["user_badge"]["is_favorite"]).to eq(true)
|
||||
expect(user_badge.reload.is_favorite).to eq(true)
|
||||
expect(user_badge2.reload.is_favorite).to eq(true)
|
||||
|
||||
put "/user_badges/#{other_user_badge.id}/toggle_favorite.json"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["user_badge"]["is_favorite"]).to eq(true)
|
||||
expect(other_user_badge.reload.is_favorite).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user