summaryrefslogtreecommitdiff
path: root/spec/finders
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-10 00:06:44 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-10 00:06:44 +0000
commit308146dc398fd4c13453048105498018459e0985 (patch)
treed843eb63c1672e4b18c483907e2cd4aa7fca708e /spec/finders
parent4b28d5ae770c6bd332283a3f13ceae06329c409b (diff)
downloadgitlab-ce-308146dc398fd4c13453048105498018459e0985.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/user_finder_spec.rb32
1 files changed, 27 insertions, 5 deletions
diff --git a/spec/finders/user_finder_spec.rb b/spec/finders/user_finder_spec.rb
index 4771b878b8e..c20d7850d68 100644
--- a/spec/finders/user_finder_spec.rb
+++ b/spec/finders/user_finder_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
describe UserFinder do
- set(:user) { create(:user) }
+ let_it_be(:user) { create(:user) }
describe '#find_by_id' do
context 'when the user exists' do
@@ -24,7 +24,7 @@ describe UserFinder do
context 'when the user does not exist' do
it 'returns nil' do
- found = described_class.new(1).find_by_id
+ found = described_class.new(-1).find_by_id
expect(found).to be_nil
end
@@ -84,7 +84,7 @@ describe UserFinder do
context 'when the user does not exist' do
it 'returns nil' do
- found = described_class.new(1).find_by_id_or_username
+ found = described_class.new(-1).find_by_id_or_username
expect(found).to be_nil
end
@@ -110,7 +110,7 @@ describe UserFinder do
context 'when the user does not exist' do
it 'raises ActiveRecord::RecordNotFound' do
- finder = described_class.new(1)
+ finder = described_class.new(-1)
expect { finder.find_by_id! }.to raise_error(ActiveRecord::RecordNotFound)
end
@@ -170,10 +170,32 @@ describe UserFinder do
context 'when the user does not exist' do
it 'raises ActiveRecord::RecordNotFound' do
- finder = described_class.new(1)
+ finder = described_class.new(-1)
expect { finder.find_by_id_or_username! }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
+
+ describe '#find_by_ssh_key_id' do
+ let_it_be(:ssh_key) { create(:key, user: user) }
+
+ it 'returns the user when passing the ssh key id' do
+ found = described_class.new(ssh_key.id).find_by_ssh_key_id
+
+ expect(found).to eq(user)
+ end
+
+ it 'returns the user when passing the ssh key id (string)' do
+ found = described_class.new(ssh_key.id.to_s).find_by_ssh_key_id
+
+ expect(found).to eq(user)
+ end
+
+ it 'returns nil when the id does not exist' do
+ found = described_class.new(-1).find_by_ssh_key_id
+
+ expect(found).to be_nil
+ end
+ end
end