Skip to content

Commit

Permalink
Hide name for users without it
Browse files Browse the repository at this point in the history
  • Loading branch information
josepegea committed Oct 26, 2024
1 parent e19870f commit d2d2e3a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def hint(close = true)
end
end

def user_name(user)
user.missing_name? ? '-' : user.name
end

private

def markdown_parser
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

module LinkHelper
def link_to_user(user, image: false, image_class: nil)
link_to(user, title: user.name) do
image ? user_image(user, image_class:) + user.name : user.name
link_to(user, title: user_name(user)) do
image ? user_image(user, image_class:) + user_name(user) : user_name(user)
end
end

def user_image(user, image_class: nil)
image_class ||= 'small-user-image'
image_tag(cache_image_path(user), title: user.name, class: image_class)
image_tag(cache_image_path(user), title: user_name(user), class: image_class)
end

def link_to_job(job)
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.card-body
h2.card-title
= user_image(user)
= "#{user.name}"
= "#{user_name(user)}"
= " (#{user.nickname})" unless user.hide_nickname?
small.text-muted
span>= I18n.tw("profile.freelancer") if user.freelancer?
Expand Down
24 changes: 21 additions & 3 deletions spec/views/users/show.html_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@

describe 'users/show' do
let(:user) { build(:user, id: 123) }
let(:dom) { Nokogiri::HTML(rendered) }

it 'renders successfully' do
allow(view).to receive_messages(current_user: user, user:)
before { allow(view).to receive_messages(current_user: user, user:) }

it 'renders successfully' do
render

expect(rendered).to include(user.nickname)
expect(dom.at_css('.card .card-body .card-title').inner_text).to include(user.nickname)
end

context 'when user was just created through email OTP' do
let(:user) { User.create_from_hash!(EMAIL_AUTH_HASH) }

it 'hides nickname' do
render

expect(dom.at_css('.card .card-body .card-title').inner_text).not_to include(user.nickname)
end

it 'shows name placeholder', :aggregate_failures do
render

expect(dom.at_css('.card .card-body .card-title').inner_text).not_to include(user.name)
expect(dom.at_css('.card .card-body .card-title').inner_text).to include('-')
end
end
end

0 comments on commit d2d2e3a

Please sign in to comment.