From f338ff43c13a6dd5c3bf90bd58c0d5cff52fc79c Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Wed, 7 Feb 2018 18:20:20 +0100 Subject: 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. --- spec/helpers/application_helper_spec.rb | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'spec/helpers/application_helper_spec.rb') 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' } -- cgit v1.2.1 From c4cf7220146f74196ef20b12cf0db3502649ac06 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Fri, 9 Feb 2018 13:28:59 +0100 Subject: Remove generic #avatar_icon helper. --- spec/helpers/application_helper_spec.rb | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'spec/helpers/application_helper_spec.rb') diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index a1fcdeca10e..96bd4c96ae4 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -63,34 +63,6 @@ describe ApplicationHelper do end end - describe 'avatar_icon' 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(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('foo@example.com', 20, 2) - end - end - end - - describe 'using a user' do - it 'returns a relative URL for the avatar' do - expect(helper.avatar_icon(user).to_s) - .to eq(user.avatar.url) - end - end - end - describe 'avatar_icon_for_email' do let(:user) { create(:user, avatar: File.open(uploaded_image_temp_path)) } -- cgit v1.2.1 From dd1d13b859c4c4cd7b6a64eb93f761c10c9262d4 Mon Sep 17 00:00:00 2001 From: Andreas Brandl Date: Tue, 13 Feb 2018 17:02:06 +0100 Subject: Extract repeated logic into #avatar_icon_for. This essentially allows to pass both user and email, so that we can either prefer the user to retrieve the avatar or (if user is not present) fall back to the email lookup. --- spec/helpers/application_helper_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/helpers/application_helper_spec.rb') diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 96bd4c96ae4..43cb0dfe163 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -63,6 +63,22 @@ describe ApplicationHelper do end end + describe 'avatar_icon_for' do + let!(:user) { create(:user, avatar: File.open(uploaded_image_temp_path), email: 'bar@example.com') } + let(:email) { 'foo@example.com' } + let!(:another_user) { create(:user, avatar: File.open(uploaded_image_temp_path), email: email) } + + it 'prefers the user to retrieve the avatar_url' do + expect(helper.avatar_icon_for(user, email).to_s) + .to eq(user.avatar.url) + end + + it 'falls back to email lookup if no user given' do + expect(helper.avatar_icon_for(nil, email).to_s) + .to eq(another_user.avatar.url) + end + end + describe 'avatar_icon_for_email' do let(:user) { create(:user, avatar: File.open(uploaded_image_temp_path)) } -- cgit v1.2.1