From 5f0351348b0e5388ddfca2e657275295b01f54c9 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 14 Jul 2017 14:15:33 +0900 Subject: [PATCH] FIX: Group name was being reverted to non-localized version. https://meta.discourse.org/t/localized-staff-group-names-changed/65360/16 --- app/models/group.rb | 9 +++------ spec/models/group_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index 11795936e60..0ec202b94b0 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -205,12 +205,9 @@ class Group < ActiveRecord::Base localized_name = I18n.t("groups.default_names.#{name}").downcase validator = UsernameValidator.new(localized_name) - group.name = - if !Group.where("LOWER(name) = ?", localized_name).exists? && validator.valid_format? - localized_name - else - name - end + if !Group.where("LOWER(name) = ?", localized_name).exists? && validator.valid_format? + group.name = localized_name + end # the everyone group is special, it can include non-users so there is no # way to have the membership in a table diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index c70426e04c9..0dc2f60ec85 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -162,6 +162,28 @@ describe Group do expect(g.visible).to eq(false) end + it "does not reset the localized name" do + begin + default_locale = SiteSetting.default_locale + I18n.locale = SiteSetting.default_locale = 'fi' + + group = Group.find(Group::AUTO_GROUPS[:everyone]) + group.update!(name: I18n.t("groups.default_names.everyone")) + + Group.refresh_automatic_group!(:everyone) + + expect(group.reload.name).to eq(I18n.t("groups.default_names.everyone")) + + I18n.locale = SiteSetting.default_locale = 'en' + + Group.refresh_automatic_group!(:everyone) + + expect(group.reload.name).to eq(I18n.t("groups.default_names.everyone")) + ensure + I18n.locale = SiteSetting.default_locale = default_locale + end + end + it "uses the localized name if name has not been taken" do begin default_locale = SiteSetting.default_locale