From 3e10ff7fc5543a90fa0fa48a1d3b9756fe7e6485 Mon Sep 17 00:00:00 2001 From: zmagod Date: Fri, 4 May 2018 10:44:23 +0200 Subject: [PATCH 1/2] add custom method that generates smart annotations name from repository name [fixes SCI-2307] --- .../smart_annotations/html_preview.rb | 10 +++- .../smart_annotations/html_preview_spec.rb | 47 ++++++++++++++++--- 2 files changed, 50 insertions(+), 7 deletions(-) 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..784366154 100644 --- a/spec/services/smart_annotations/html_preview_spec.rb +++ b/spec/services/smart_annotations/html_preview_spec.rb @@ -52,12 +52,47 @@ 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 + + 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 end end From 69783cb73e2440d2f2cc41d467301044f9de7751 Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 16 May 2018 12:11:18 +0200 Subject: [PATCH 2/2] removes unneeded spec --- spec/services/smart_annotations/html_preview_spec.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spec/services/smart_annotations/html_preview_spec.rb b/spec/services/smart_annotations/html_preview_spec.rb index 784366154..fb79699c2 100644 --- a/spec/services/smart_annotations/html_preview_spec.rb +++ b/spec/services/smart_annotations/html_preview_spec.rb @@ -86,13 +86,6 @@ describe SmartAnnotations::HtmlPreview do ) expect(trimmed_repository_name).to eq('Two') 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 end end