Merge pull request #1127 from ZmagoD/zd_SCI_2307_v3

Adds custom method that generates smart annotations name for repository
This commit is contained in:
Zmago Devetak 2018-05-16 13:23:25 +02:00 committed by GitHub
commit 8a92f1a499
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 7 deletions

View file

@ -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

View file

@ -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