summaryrefslogtreecommitdiff
path: root/spec/helpers/application_helper_spec.rb
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2018-02-07 18:20:20 +0100
committerAndreas Brandl <abrandl@gitlab.com>2018-02-13 18:04:50 +0100
commitf338ff43c13a6dd5c3bf90bd58c0d5cff52fc79c (patch)
treeea9de3b7767a968b1b7e7df1b667d92edcd76f57 /spec/helpers/application_helper_spec.rb
parent16908f9718820dd651faa61396fedb997d10eadd (diff)
downloadgitlab-ce-f338ff43c13a6dd5c3bf90bd58c0d5cff52fc79c.tar.gz
Refactor and split ApplicationHelper#avatar_icon.
When we don't use the original `ApplicationHelper#avatar_icon` anymore, we can just remove it (and its specs). Closes #42800.
Diffstat (limited to 'spec/helpers/application_helper_spec.rb')
-rw-r--r--spec/helpers/application_helper_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index f7a4a7afced..a1fcdeca10e 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -91,6 +91,54 @@ describe ApplicationHelper do
end
end
+ describe 'avatar_icon_for_email' do
+ let(:user) { create(:user, avatar: File.open(uploaded_image_temp_path)) }
+
+ context 'using an email' do
+ context 'when there is a matching user' do
+ it 'returns a relative URL for the avatar' do
+ expect(helper.avatar_icon_for_email(user.email).to_s)
+ .to eq(user.avatar.url)
+ end
+ end
+
+ context 'when no user exists for the email' do
+ it 'calls gravatar_icon' do
+ expect(helper).to receive(:gravatar_icon).with('foo@example.com', 20, 2)
+
+ helper.avatar_icon_for_email('foo@example.com', 20, 2)
+ end
+ end
+
+ context 'without an email passed' do
+ it 'calls gravatar_icon' do
+ expect(helper).to receive(:gravatar_icon).with(nil, 20, 2)
+
+ helper.avatar_icon_for_email(nil, 20, 2)
+ end
+ end
+ end
+ end
+
+ describe 'avatar_icon_for_user' do
+ let(:user) { create(:user, avatar: File.open(uploaded_image_temp_path)) }
+
+ 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
+ end
+
+ context 'without a user object passed' do
+ it 'calls gravatar_icon' do
+ expect(helper).to receive(:gravatar_icon).with(nil, 20, 2)
+
+ helper.avatar_icon_for_user(nil, 20, 2)
+ end
+ end
+ end
+
describe 'gravatar_icon' do
let(:user_email) { 'user@email.com' }