diff --git a/app/services/smart_annotations/html_preview.rb b/app/services/smart_annotations/html_preview.rb index 39ae0e47e..9e87ea974 100644 --- a/app/services/smart_annotations/html_preview.rb +++ b/app/services/smart_annotations/html_preview.rb @@ -56,7 +56,15 @@ module SmartAnnotations end def trim_repository_name(name) - name.strip.slice(0..2).capitalize + splited_name = name.split + size = splited_name.size + return name.strip.slice(0..2).capitalize if size == 1 + generate_name_from_array(splited_name, size).capitalize + end + + def generate_name_from_array(names, size) + return "#{names[0].slice(0..1)}#{names[1][0]}" if size == 2 + "#{names[0][0]}#{names[1][0]}#{names[2][0]}" end end end diff --git a/spec/services/smart_annotations/html_preview_spec.rb b/spec/services/smart_annotations/html_preview_spec.rb index 8b2f4f9cc..fb79699c2 100644 --- a/spec/services/smart_annotations/html_preview_spec.rb +++ b/spec/services/smart_annotations/html_preview_spec.rb @@ -52,12 +52,40 @@ describe SmartAnnotations::HtmlPreview do end end - describe '#trim_repository_name/1' do - it 'is returns a 3 letter upcase string' do - trimmed_repository_name = subject.__send__( - :trim_repository_name, 'banana' - ) - expect(trimmed_repository_name).to eq('Ban') + context '#trim_repository_name/1' do + describe 'repository name with one word' do + it 'is returns a 3 letter capitalize string' do + trimmed_repository_name = subject.__send__( + :trim_repository_name, 'banana' + ) + expect(trimmed_repository_name).to eq('Ban') + end + end + + describe 'repository name with two words' do + it 'returns the first two letters of first word ' \ + 'and the first letter of second word' do + trimmed_repository_name = subject.__send__( + :trim_repository_name, 'two words' + ) + expect(trimmed_repository_name).to eq('Tww') + end + + it 'does not return 3 letters of the first word' do + trimmed_repository_name = subject.__send__( + :trim_repository_name, 'two words' + ) + expect(trimmed_repository_name).not_to eq('Two') + end + end + + describe 'repository name with three words' do + it 'returns the first letter of first 3 words capitalized' do + trimmed_repository_name = subject.__send__( + :trim_repository_name, 'two words of wisdom' + ) + expect(trimmed_repository_name).to eq('Two') + end end end end