diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-25 06:11:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-25 06:11:34 +0300 |
commit | 25e6ceaf36f60086b527e0a527dbcb57a3ce3934 (patch) | |
tree | e1a10d597fb9305a49dfc1ae44bee09848eab5a2 /spec | |
parent | 706338ea16ff0be915765ccc79429a50d0ff2edc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/helpers/avatars_helper_spec.rb | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/spec/helpers/avatars_helper_spec.rb b/spec/helpers/avatars_helper_spec.rb index a6195e47c30..192e48f43e5 100644 --- a/spec/helpers/avatars_helper_spec.rb +++ b/spec/helpers/avatars_helper_spec.rb @@ -146,11 +146,52 @@ RSpec.describe AvatarsHelper do describe '#avatar_icon_for_user' do let(:user) { create(:user, avatar: File.open(uploaded_image_temp_path)) } + shared_examples 'blocked or unconfirmed user with avatar' do + context 'when the viewer is not an admin' do + let!(:viewing_user) { create(:user) } + + it 'returns the default avatar' do + expect(helper.avatar_icon_for_user(user, current_user: viewing_user).to_s) + .to match_asset_path(described_class::DEFAULT_AVATAR_PATH) + end + end + + context 'when the viewer is an admin', :enable_admin_mode do + let!(:viewing_user) { create(:user, :admin) } + + it 'returns the default avatar when the user is not passed' do + expect(helper.avatar_icon_for_user(user).to_s) + .to match_asset_path(described_class::DEFAULT_AVATAR_PATH) + end + + it 'returns the user avatar when the user is passed' do + expect(helper.avatar_icon_for_user(user, current_user: viewing_user).to_s) + .to eq(user.avatar.url) + end + end + end + context 'with a user object passed' do it 'returns a relative URL for the avatar' do expect(helper.avatar_icon_for_user(user).to_s) .to eq(user.avatar.url) end + + context 'when the user is blocked' do + before do + user.block! + end + + it_behaves_like 'blocked or unconfirmed user with avatar' + end + + context 'when the user is unconfirmed' do + before do + user.update!(confirmed_at: nil) + end + + it_behaves_like 'blocked or unconfirmed user with avatar' + end end context 'without a user object passed' do @@ -171,7 +212,7 @@ RSpec.describe AvatarsHelper do end it 'returns a generic avatar' do - expect(helper.gravatar_icon(user_email)).to match_asset_path('no_avatar.png') + expect(helper.gravatar_icon(user_email)).to match_asset_path(described_class::DEFAULT_AVATAR_PATH) end end @@ -181,7 +222,7 @@ RSpec.describe AvatarsHelper do end it 'returns a generic avatar when email is blank' do - expect(helper.gravatar_icon('')).to match_asset_path('no_avatar.png') + expect(helper.gravatar_icon('')).to match_asset_path(described_class::DEFAULT_AVATAR_PATH) end it 'returns a valid Gravatar URL' do |