From 1bd9306cedc22576ee4bf4af5bc1ba4057dc566f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 13 Dec 2024 04:21:55 -0500 Subject: [PATCH] Add coverage for `Tag` model validations on name/display_name (#33291) --- spec/models/tag_spec.rb | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index 18dd26be94..a1cc6a064f 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -5,7 +5,39 @@ require 'rails_helper' RSpec.describe Tag do include_examples 'Reviewable' - describe 'validations' do + describe 'Validations' do + describe 'name' do + context 'with a new record' do + subject { Fabricate.build :tag, name: 'original' } + + it { is_expected.to allow_value('changed').for(:name) } + end + + context 'with an existing record' do + subject { Fabricate :tag, name: 'original' } + + it { is_expected.to_not allow_value('changed').for(:name).with_message(previous_name_error_message) } + end + end + + describe 'display_name' do + context 'with a new record' do + subject { Fabricate.build :tag, name: 'original', display_name: 'OriginalDisplayName' } + + it { is_expected.to allow_value('ChangedDisplayName').for(:display_name) } + end + + context 'with an existing record' 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) } + end + end + + def previous_name_error_message + I18n.t('tags.does_not_match_previous_name') + end + it 'invalid with #' do expect(described_class.new(name: '#hello_world')).to_not be_valid end