Skip to content

Commit bbd7870

Browse files
authored
FIX: users#show crashing for users without email (#1076)
1 parent 2efb197 commit bbd7870

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

app/models/user.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def hash_for_email(email)
9898
end
9999

100100
def nickname_from_email(email)
101-
hash_for_email(email)
101+
hash_for_email(email) if email.present?
102102
end
103103

104104
def hide_nickname?

spec/controllers/users_controller_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
get :show, params: { id: user_with_participations.id }
2727
expect(response).to be_ok
2828
end
29+
30+
context 'when user has no email' do
31+
render_views
32+
33+
before { user.update!(email: nil) }
34+
35+
it 'does not fail' do
36+
get :show, params: { id: user.id }
37+
expect(response).to be_ok
38+
end
39+
end
2940
end
3041

3142
context 'GET :edit' do

0 commit comments

Comments
 (0)