fix: Undefined method `length' for nil:NilClass (#8491)
This commit is contained in:
@@ -64,6 +64,8 @@ module PortalHelper
|
|||||||
|
|
||||||
def thumbnail_bg_color(username)
|
def thumbnail_bg_color(username)
|
||||||
colors = ['#6D95BA', '#A4C3C3', '#E19191']
|
colors = ['#6D95BA', '#A4C3C3', '#E19191']
|
||||||
|
return colors.sample if username.blank?
|
||||||
|
|
||||||
colors[username.length % colors.size]
|
colors[username.length % colors.size]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ describe PortalHelper do
|
|||||||
|
|
||||||
describe '#thumbnail_bg_color' do
|
describe '#thumbnail_bg_color' do
|
||||||
it 'returns the correct color based on username length' do
|
it 'returns the correct color based on username length' do
|
||||||
expect(helper.thumbnail_bg_color('')).to eq('#6D95BA') # Length 0, so index is 0
|
expect(helper.thumbnail_bg_color('')).to be_in(['#6D95BA', '#A4C3C3', '#E19191'])
|
||||||
expect(helper.thumbnail_bg_color('Joe')).to eq('#6D95BA') # Length 3, so index is 0
|
expect(helper.thumbnail_bg_color('Joe')).to eq('#6D95BA') # Length 3, so index is 0
|
||||||
expect(helper.thumbnail_bg_color('John')).to eq('#A4C3C3') # Length 4, so index is 1
|
expect(helper.thumbnail_bg_color('John')).to eq('#A4C3C3') # Length 4, so index is 1
|
||||||
expect(helper.thumbnail_bg_color('Jane james')).to eq('#A4C3C3') # Length 10, so index is 1
|
expect(helper.thumbnail_bg_color('Jane james')).to eq('#A4C3C3') # Length 10, so index is 1
|
||||||
|
|||||||
Reference in New Issue
Block a user