Add coverage for Tag model validations on name/display_name (#33291)
				
					
				
			This commit is contained in:
		
							parent
							
								
									4f2d060f94
								
							
						
					
					
						commit
						1bd9306ced
					
				| @ -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 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user