diff options
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 16 |
2 files changed, 16 insertions, 4 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 088a7cb83d5..7d71b0773e0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -351,7 +351,9 @@ class User < ActiveRecord::Base def find_by_full_path(path, follow_redirects: false) namespace = Namespace.find_by_full_path(path, follow_redirects: follow_redirects) - namespace&.owner + return unless namespace && namespace.kind == 'user' + + namespace.owner end def reference_prefix diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e6e7774431e..6a15830a15c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -929,10 +929,20 @@ describe User, models: true do end context 'with a group route matching the given path' do - let!(:group) { create(:group, path: 'group_path') } + context 'when the group namespace has an owner_id (legacy data)' do + let!(:group) { create(:group, path: 'group_path', owner: user) } - it 'returns nil' do - expect(User.find_by_full_path('group_path')).to eq(nil) + it 'returns nil' do + expect(User.find_by_full_path('group_path')).to eq(nil) + end + end + + context 'when the group namespace does not have an owner_id' do + let!(:group) { create(:group, path: 'group_path') } + + it 'returns nil' do + expect(User.find_by_full_path('group_path')).to eq(nil) + end end end end |