diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-10-04 18:03:10 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-10-04 22:33:14 +0200 |
commit | f8522ee5f5be14b4132c115cad43978c9fd39a55 (patch) | |
tree | 7bc729fb96bebd7ac897d4b847a3ce3142d0c8bf /spec/models/user_spec.rb | |
parent | 7887a3dafb6902cc39c831e307c48faf49f80b51 (diff) | |
download | gitlab-ce-test-improve-gitlab-identifier.tar.gz |
Refactor Gitlab::Identifiertest-improve-gitlab-identifier
This refactors Gitlab::Identifier so it uses fewer queries and is
actually tested. Queries are reduced by caching the output as well as
using 1 query (instead of 2) to find a user using an SSH key.
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a1770d96f83..65b2896930a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -610,6 +610,23 @@ describe User, models: true do end end + describe '.find_by_ssh_key_id' do + context 'using an existing SSH key ID' do + let(:user) { create(:user) } + let(:key) { create(:key, user: user) } + + it 'returns the corresponding User' do + expect(described_class.find_by_ssh_key_id(key.id)).to eq(user) + end + end + + context 'using an invalid SSH key ID' do + it 'returns nil' do + expect(described_class.find_by_ssh_key_id(-1)).to be_nil + end + end + end + describe '.by_login' do let(:username) { 'John' } let!(:user) { create(:user, username: username) } |