diff options
Diffstat (limited to 'spec/helpers/avatars_helper_spec.rb')
-rw-r--r-- | spec/helpers/avatars_helper_spec.rb | 159 |
1 files changed, 96 insertions, 63 deletions
diff --git a/spec/helpers/avatars_helper_spec.rb b/spec/helpers/avatars_helper_spec.rb index bf23c74c0f0..dd0d6d1246f 100644 --- a/spec/helpers/avatars_helper_spec.rb +++ b/spec/helpers/avatars_helper_spec.rb @@ -102,7 +102,7 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do end describe '#avatar_icon_for_email', :clean_gitlab_redis_cache do - let(:user) { create(:user, :public_email, avatar: File.open(uploaded_image_temp_path)) } + let(:user) { create(:user, :public_email, :commit_email, avatar: File.open(uploaded_image_temp_path)) } subject { helper.avatar_icon_for_email(user.email).to_s } @@ -131,13 +131,22 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do end context 'without an email passed' do - it 'calls gravatar_icon' do - expect(helper).to receive(:gravatar_icon).with(nil, 20, 2) - expect(User).not_to receive(:find_by_any_email) + it 'returns the default avatar' do + expect(helper).to receive(:default_avatar) + expect(User).not_to receive(:with_public_email) helper.avatar_icon_for_email(nil, 20, 2) end end + + context 'with a blank email address' do + it 'returns the default avatar' do + expect(helper).to receive(:default_avatar) + expect(User).not_to receive(:with_public_email) + + helper.avatar_icon_for_email('', 20, 2) + end + end end end @@ -305,22 +314,26 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do subject { helper.user_avatar_without_link(options) } it 'displays user avatar' do - is_expected.to eq tag.img(alt: "#{user.name}'s avatar", - src: avatar_icon_for_user(user, 16), - data: { container: 'body' }, - class: 'avatar s16 has-tooltip', - title: user.name) + is_expected.to eq tag.img( + alt: "#{user.name}'s avatar", + src: avatar_icon_for_user(user, 16), + data: { container: 'body' }, + class: 'avatar s16 has-tooltip', + title: user.name + ) end context 'with css_class parameter' do let(:options) { { user: user, css_class: '.cat-pics' } } it 'uses provided css_class' do - is_expected.to eq tag.img(alt: "#{user.name}'s avatar", - src: avatar_icon_for_user(user, 16), - data: { container: 'body' }, - class: "avatar s16 #{options[:css_class]} has-tooltip", - title: user.name) + is_expected.to eq tag.img( + alt: "#{user.name}'s avatar", + src: avatar_icon_for_user(user, 16), + data: { container: 'body' }, + class: "avatar s16 #{options[:css_class]} has-tooltip", + title: user.name + ) end end @@ -328,11 +341,13 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do let(:options) { { user: user, size: 99 } } it 'uses provided size' do - is_expected.to eq tag.img(alt: "#{user.name}'s avatar", - src: avatar_icon_for_user(user, options[:size]), - data: { container: 'body' }, - class: "avatar s#{options[:size]} has-tooltip", - title: user.name) + is_expected.to eq tag.img( + alt: "#{user.name}'s avatar", + src: avatar_icon_for_user(user, options[:size]), + data: { container: 'body' }, + class: "avatar s#{options[:size]} has-tooltip", + title: user.name + ) end end @@ -340,11 +355,13 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do let(:options) { { user: user, url: '/over/the/rainbow.png' } } it 'uses provided url' do - is_expected.to eq tag.img(alt: "#{user.name}'s avatar", - src: options[:url], - data: { container: 'body' }, - class: "avatar s16 has-tooltip", - title: user.name) + is_expected.to eq tag.img( + alt: "#{user.name}'s avatar", + src: options[:url], + data: { container: 'body' }, + class: "avatar s16 has-tooltip", + title: user.name + ) end end @@ -352,11 +369,13 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do let(:options) { { user: user, lazy: true } } it 'adds `lazy` class to class list, sets `data-src` with avatar URL and `src` with placeholder image' do - is_expected.to eq tag.img(alt: "#{user.name}'s avatar", - src: LazyImageTagHelper.placeholder_image, - data: { container: 'body', src: avatar_icon_for_user(user, 16) }, - class: "avatar s16 has-tooltip lazy", - title: user.name) + is_expected.to eq tag.img( + alt: "#{user.name}'s avatar", + src: LazyImageTagHelper.placeholder_image, + data: { container: 'body', src: avatar_icon_for_user(user, 16) }, + class: "avatar s16 has-tooltip lazy", + title: user.name + ) end end @@ -365,11 +384,13 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do let(:options) { { user: user, has_tooltip: true } } it 'adds has-tooltip' do - is_expected.to eq tag.img(alt: "#{user.name}'s avatar", - src: avatar_icon_for_user(user, 16), - data: { container: 'body' }, - class: "avatar s16 has-tooltip", - title: user.name) + is_expected.to eq tag.img( + alt: "#{user.name}'s avatar", + src: avatar_icon_for_user(user, 16), + data: { container: 'body' }, + class: "avatar s16 has-tooltip", + title: user.name + ) end end @@ -377,10 +398,12 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do let(:options) { { user: user, has_tooltip: false } } it 'does not add has-tooltip or data container' do - is_expected.to eq tag.img(alt: "#{user.name}'s avatar", - src: avatar_icon_for_user(user, 16), - class: "avatar s16", - title: user.name) + is_expected.to eq tag.img( + alt: "#{user.name}'s avatar", + src: avatar_icon_for_user(user, 16), + class: "avatar s16", + title: user.name + ) end end end @@ -392,20 +415,24 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do let(:options) { { user: user, user_name: 'Tinky Winky' } } it 'prefers user parameter' do - is_expected.to eq tag.img(alt: "#{user.name}'s avatar", - src: avatar_icon_for_user(user, 16), - data: { container: 'body' }, - class: "avatar s16 has-tooltip", - title: user.name) + is_expected.to eq tag.img( + alt: "#{user.name}'s avatar", + src: avatar_icon_for_user(user, 16), + data: { container: 'body' }, + class: "avatar s16 has-tooltip", + title: user.name + ) end end it 'uses user_name and user_email parameter if user is not present' do - is_expected.to eq tag.img(alt: "#{options[:user_name]}'s avatar", - src: helper.avatar_icon_for_email(options[:user_email], 16), - data: { container: 'body' }, - class: "avatar s16 has-tooltip", - title: options[:user_name]) + is_expected.to eq tag.img( + alt: "#{options[:user_name]}'s avatar", + src: helper.avatar_icon_for_email(options[:user_email], 16), + data: { container: 'body' }, + class: "avatar s16 has-tooltip", + title: options[:user_name] + ) end end @@ -416,11 +443,13 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do let(:options) { { user: user_with_avatar, only_path: false } } it 'will return avatar with a full path' do - is_expected.to eq tag.img(alt: "#{user_with_avatar.name}'s avatar", - src: avatar_icon_for_user(user_with_avatar, 16, only_path: false), - data: { container: 'body' }, - class: "avatar s16 has-tooltip", - title: user_with_avatar.name) + is_expected.to eq tag.img( + alt: "#{user_with_avatar.name}'s avatar", + src: avatar_icon_for_user(user_with_avatar, 16, only_path: false), + data: { container: 'body' }, + class: "avatar s16 has-tooltip", + title: user_with_avatar.name + ) end end @@ -428,11 +457,13 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do let(:options) { { user_email: user_with_avatar.email, user_name: user_with_avatar.username, only_path: false } } it 'will return avatar with a full path' do - is_expected.to eq tag.img(alt: "#{user_with_avatar.username}'s avatar", - src: helper.avatar_icon_for_email(user_with_avatar.email, 16, only_path: false), - data: { container: 'body' }, - class: "avatar s16 has-tooltip", - title: user_with_avatar.username) + is_expected.to eq tag.img( + alt: "#{user_with_avatar.username}'s avatar", + src: helper.avatar_icon_for_email(user_with_avatar.email, 16, only_path: false), + data: { container: 'body' }, + class: "avatar s16 has-tooltip", + title: user_with_avatar.username + ) end end end @@ -455,11 +486,13 @@ RSpec.describe AvatarsHelper, feature_category: :source_code_management do let(:resource) { user.namespace } it 'displays user avatar' do - is_expected.to eq tag.img(alt: "#{user.name}'s avatar", - src: avatar_icon_for_user(user, 32), - data: { container: 'body' }, - class: 'avatar s32 has-tooltip', - title: user.name) + is_expected.to eq tag.img( + alt: "#{user.name}'s avatar", + src: avatar_icon_for_user(user, 32), + data: { container: 'body' }, + class: 'avatar s32 has-tooltip', + title: user.name + ) end end |