New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Badge and user title interaction fixes #8282
Changes from 1 commit
11ffc5a
451e9dc
3d976a9
787bf1f
aa262b2
46bf8f1
01dd6f0
c784c1d
5382c10
a31a93b
File filter...
Jump to…
Fix user title logic when badge name customized
* fix an issue where a user's title was not considered a badge granted title when the user used a badge for their title and the badge name was customized. this affected the effectiveness of revoke_ungranted_titles! which only operates on badge_granted_titles * when a user's title is set now it is considered a badge_granted_title if the badge name OR the badge custom name from TranslationOverride is the same as the title * when a user's badge is revoked we now also revoke their title if the user's title matches the badge name OR the badge custom name from TranslationOverride * add a user history log when the title is revoked to remove confusion about why titles are revoked
- Loading branch information
@@ -1997,12 +1997,33 @@ def filter_by(method) | ||
expect(user.user_profile.reload.badge_granted_title).to eq(false) | ||
|
||
badge.update!(allow_title: true) | ||
user.badges.reload | ||
martin-brennan
Author
Contributor
|
||
user.update!(title: badge.name) | ||
expect(user.user_profile.reload.badge_granted_title).to eq(true) | ||
|
||
user.update!(title: nil) | ||
expect(user.user_profile.reload.badge_granted_title).to eq(false) | ||
end | ||
|
||
context 'when a custom badge name has been set and it matches the title' do | ||
let(:customized_badge_name) { 'Merit Badge' } | ||
|
||
before do | ||
TranslationOverride.upsert!(I18n.locale, Badge.i18n_key(badge.name), customized_badge_name) | ||
end | ||
|
||
it 'sets badge_granted_title correctly' do | ||
BadgeGranter.grant(badge, user) | ||
|
||
badge.update!(allow_title: true) | ||
user.update!(title: customized_badge_name) | ||
expect(user.user_profile.reload.badge_granted_title).to eq(true) | ||
end | ||
|
||
after do | ||
TranslationOverride.revert!(I18n.locale, Badge.i18n_key(badge.name)) | ||
end | ||
end | ||
end | ||
|
||
describe '#next_best_title' do | ||
We don't need to reload the badges here. Since we only set the title of user.