From db3bc89792c5450cb93e674d621d5ea996ee01f6 Mon Sep 17 00:00:00 2001 From: Maxim Rydkin Date: Fri, 1 Sep 2017 00:43:13 +0300 Subject: [PATCH] refactor `app/helpers/projects_helper.rb:21:3` --- .rubocop.yml | 2 +- app/helpers/projects_helper.rb | 4 ++-- spec/helpers/projects_helper_spec.rb | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 16f2e4484fc..4640681379a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -643,7 +643,7 @@ Metrics/ClassLength: # of test cases needed to validate a method. Metrics/CyclomaticComplexity: Enabled: true - Max: 15 + Max: 14 # Limit lines to 80 characters. Metrics/LineLength: diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 86665ea2aec..7e5b214b1c7 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -17,7 +17,7 @@ module ProjectsHelper def link_to_member_avatar(author, opts = {}) default_opts = { avatar: true, name: true, size: 16, author_class: 'author', title: ":name" } opts = default_opts.merge(opts) - image_tag(avatar_icon(author, opts[:size]), width: opts[:size], class: "avatar avatar-inline #{"s#{opts[:size]}" if opts[:size]}", alt: '') if opts[:avatar] + image_tag(avatar_icon(author, opts[:size]), width: opts[:size], class: ['avatar', 'avatar-inline', "#{"s#{opts[:size]}" if opts[:size]}", opts[:avatar_class]].reject(&:blank?), alt: '') if opts[:avatar] end def link_to_member(project, author, opts = {}, &block) @@ -29,7 +29,7 @@ module ProjectsHelper author_html = "" # Build avatar image tag - author_html << image_tag(avatar_icon(author, opts[:size]), width: opts[:size], class: "avatar avatar-inline #{"s#{opts[:size]}" if opts[:size]} #{opts[:avatar_class] if opts[:avatar_class]}", alt: '') if opts[:avatar] + author_html << link_to_member_avatar(author, opts) if opts[:avatar] # Build name span tag if opts[:by_username] diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index d1efa318d14..93a5b55e4d0 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -191,7 +191,15 @@ describe ProjectsHelper do end end - describe 'link_to_member' do + describe '#link_to_member_avatar' do + let(:user) { create(:user) } + + it 'returns image tag for member avatar' do + expect(helper.link_to_member_avatar(user)).to eq("\"\"") + end + end + + describe '#link_to_member' do let(:group) { create(:group) } let(:project) { create(:project, group: group) } let(:user) { create(:user) }