Fix Style/GuardClause in Tag (#35522)

This commit is contained in:
Matt Jankowski 2025-07-28 04:54:29 -04:00 committed by GitHub
parent eb73ae2f86
commit 040a638ab9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -164,9 +164,10 @@ class Tag < ApplicationRecord
end
def validate_display_name_change
unless HashtagNormalizer.new.normalize(display_name).casecmp(name).zero?
errors.add(:display_name,
I18n.t('tags.does_not_match_previous_name'))
end
errors.add(:display_name, I18n.t('tags.does_not_match_previous_name')) unless display_name_matches_name?
end
def display_name_matches_name?
HashtagNormalizer.new.normalize(display_name).casecmp(name).zero?
end
end

View File

@ -17,6 +17,7 @@ RSpec.describe Tag do
subject { Fabricate :tag, name: 'original' }
it { is_expected.to_not allow_value('changed').for(:name).with_message(previous_name_error_message) }
it { is_expected.to allow_value('ORIGINAL').for(:name) }
end
end
@ -31,6 +32,7 @@ RSpec.describe Tag do
subject { Fabricate :tag, name: 'original', display_name: 'OriginalDisplayName' }
it { is_expected.to_not allow_value('ChangedDisplayName').for(:display_name).with_message(previous_name_error_message) }
it { is_expected.to allow_value('ORIGINAL').for(:display_name) }
end
end