Skip to content

A platform for community discussion. Free, open, simple.

FIX: Don't overwrite translated titles when updating badge (#33731)

Ted Johansson25bb2b7913dd
diff --git a/app/controllers/admin/badges_controller.rb b/app/controllers/admin/badges_controller.rb
index 4723622c25d..198cd967b1d 100644
--- a/app/controllers/admin/badges_controller.rb
+++ b/app/controllers/admin/badges_controller.rb
@@ -214,10 +214,10 @@ class Admin::BadgesController < Admin::AdminController
badge.save!
end
- if opts[:new].blank?
+ if opts[:new].blank? && badge.name_previously_changed?
Jobs.enqueue(
:bulk_user_title_update,
- new_title: badge.name,
+ new_title: badge.display_name,
granted_badge_id: badge.id,
action: Jobs::BulkUserTitleUpdate::UPDATE_ACTION,
)
diff --git a/spec/requests/admin/badges_controller_spec.rb b/spec/requests/admin/badges_controller_spec.rb
index 4deeb792b40..c794208406a 100644
--- a/spec/requests/admin/badges_controller_spec.rb
+++ b/spec/requests/admin/badges_controller_spec.rb
@@ -351,22 +351,49 @@ RSpec.describe Admin::BadgesController do
context "when there is a user with a title granted using the badge" do
fab!(:user_with_badge_title, :active_user)
- fab!(:badge) { Fabricate(:badge, name: "Oathbreaker", allow_title: true) }
- before do
- BadgeGranter.grant(badge, user_with_badge_title)
- user_with_badge_title.update(title: "Oathbreaker")
+ before { BadgeGranter.grant(badge, user_with_badge_title) }
+
+ context "when the name of the badge hasn't changed" do
+ it "does not fire a title updating job" do
+ expect_not_enqueued_with(job: :bulk_user_title_update) do
+ put "/admin/badges/#{badge.id}.json", params: { name: badge.name }
+ end
+ end
+ end
+
+ context "when using default locale" do
+ it "updates the user title in a job" do
+ user_with_badge_title.update(title: "First Like")
+
+ expect_enqueued_with(
+ job: :bulk_user_title_update,
+ args: {
+ new_title: "First Ever Like",
+ granted_badge_id: badge.id,
+ action: Jobs::BulkUserTitleUpdate::UPDATE_ACTION,
+ },
+ ) { put "/admin/badges/#{badge.id}.json", params: { name: "First Ever Like" } }
+ end
end
- it "updates the user title in a job" do
- expect_enqueued_with(
- job: :bulk_user_title_update,
- args: {
- new_title: "Shieldbearer",
- granted_badge_id: badge.id,
- action: Jobs::BulkUserTitleUpdate::UPDATE_ACTION,
- },
- ) { put "/admin/badges/#{badge.id}.json", params: { name: "Shieldbearer" } }
+ context "when using a custom locale" do
+ it "updates the title in the custom locale" do
+ SiteSetting.default_locale = "sv"
+
+ user_with_badge_title.update(title: "Första Gillningen")
+
+ expect_enqueued_with(
+ job: :bulk_user_title_update,
+ args: {
+ new_title: "Första Gillningen Någonsin",
+ granted_badge_id: badge.id,
+ action: Jobs::BulkUserTitleUpdate::UPDATE_ACTION,
+ },
+ ) do
+ put "/admin/badges/#{badge.id}.json", params: { name: "Första Gillningen Någonsin" }
+ end
+ end
end
end
end