Skip to content
Snippets Groups Projects

Make getting a user by the username case insensitive

Merged William George requested to merge awgeorge1/gitlab-ce:master into master
All threads resolved!
Compare and Show latest version
1 file
+ 61
53
Compare changes
  • Side-by-side
  • Inline
@@ -5,10 +5,10 @@
@@ -5,10 +5,10 @@
describe UserFinder do
describe UserFinder do
set(:user) { create(:user) }
set(:user) { create(:user) }
describe '#execute' do
describe '#find_by_id' do
context 'when the user exists (id)' do
context 'when the user exists' do
it 'returns the user' do
it 'returns the user' do
found = described_class.new(user.id).execute
found = described_class.new(user.id).find_by_id
expect(found).to eq(user)
expect(found).to eq(user)
end
end
@@ -16,57 +16,61 @@
@@ -16,57 +16,61 @@
context 'when the user exists (id as string)' do
context 'when the user exists (id as string)' do
it 'returns the user' do
it 'returns the user' do
found = described_class.new(user.id.to_s).execute
found = described_class.new(user.id.to_s).find_by_id
expect(found).to eq(user)
expect(found).to eq(user)
end
end
end
end
context 'when the user exists (username)' do
context 'when the user does not exist' do
it 'returns the user' do
it 'returns nil' do
found = described_class.new(user.username).execute
found = described_class.new(1).find_by_id
expect(found).to eq(user)
expect(found).to be_nil
end
end
end
end
 
end
context 'when passing a non existing username to the id' do
describe '#find_by_username' do
it 'returns nil' do
context 'when the user exists' do
found = described_class.new("non_existent_username").find_by_id
it 'returns the user' do
 
found = described_class.new(user.username).find_by_username
expect(found).to be_nil
expect(found).to eq(user)
end
end
end
end
context 'when passing an existing username to the id' do
context 'when the user does not exist' do
it 'returns nil' do
it 'returns nil' do
found = described_class.new(user.username).find_by_id
found = described_class.new("non_existent_username").find_by_username
expect(found).to be_nil
expect(found).to be_nil
end
end
end
end
 
end
context 'when passing a non existing id to the username' do
describe '#execute' do
it 'returns nil' do
context 'when the user exists (id)' do
found = described_class.new(1).find_by_username
it 'returns the user' do
 
found = described_class.new(user.id).execute
expect(found).to be_nil
expect(found).to eq(user)
end
end
end
end
context 'when passing an existing id to the username' do
context 'when the user exists (id as string)' do
it 'returns nil' do
it 'returns the user' do
found = described_class.new(user.id).find_by_username
found = described_class.new(user.id.to_s).execute
expect(found).to be_nil
expect(found).to eq(user)
end
end
end
end
context 'when passing an existing id (as string) to the username' do
context 'when the user exists (username)' do
it 'returns nil' do
it 'returns the user' do
found = described_class.new(user.id.to_s).find_by_username
found = described_class.new(user.username).execute
expect(found).to be_nil
expect(found).to eq(user)
end
end
end
end
@@ -87,10 +91,10 @@
@@ -87,10 +91,10 @@
end
end
end
end
describe '#execute!' do
describe '#find_by_id!' do
context 'when the user exists (id)' do
context 'when the user exists' do
it 'returns the user' do
it 'returns the user' do
found = described_class.new(user.id).execute!
found = described_class.new(user.id).find_by_id!
expect(found).to eq(user)
expect(found).to eq(user)
end
end
@@ -98,57 +102,61 @@
@@ -98,57 +102,61 @@
context 'when the user exists (id as string)' do
context 'when the user exists (id as string)' do
it 'returns the user' do
it 'returns the user' do
found = described_class.new(user.id.to_s).execute!
found = described_class.new(user.id.to_s).find_by_id!
expect(found).to eq(user)
expect(found).to eq(user)
end
end
end
end
context 'when the user exists (username)' do
context 'when the user does not exist' do
it 'returns the user' do
it 'raises ActiveRecord::RecordNotFound' do
found = described_class.new(user.username).execute!
finder = described_class.new(1)
expect(found).to eq(user)
expect { finder.find_by_id! }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
end
 
end
context 'when passing a non existing username to the id' do
describe '#find_by_username!' do
it 'raises ActiveRecord::RecordNotFound' do
context 'when the user exists' do
finder = described_class.new("non_existent_username")
it 'returns the user' do
 
found = described_class.new(user.username).find_by_username!
expect { finder.find_by_id! }.to raise_error(ActiveRecord::RecordNotFound)
expect(found).to eq(user)
end
end
end
end
context 'when passing an existing username to the id' do
context 'when the user does not exist' do
it 'raises ActiveRecord::RecordNotFound' do
it 'raises ActiveRecord::RecordNotFound' do
finder = described_class.new(user.username)
finder = described_class.new("non_existent_username")
expect { finder.find_by_id! }.to raise_error(ActiveRecord::RecordNotFound)
expect { finder.find_by_username! }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
end
 
end
context 'when passing a non existing id to the username' do
describe '#execute!' do
it 'raises ActiveRecord::RecordNotFound' do
context 'when the user exists (id)' do
finder = described_class.new(1)
it 'returns the user' do
 
found = described_class.new(user.id).execute!
expect { finder.find_by_username! }.to raise_error(ActiveRecord::RecordNotFound)
expect(found).to eq(user)
end
end
end
end
context 'when passing an existing id to the username' do
context 'when the user exists (id as string)' do
it 'raises ActiveRecord::RecordNotFound' do
it 'returns the user' do
finder = described_class.new(user.id)
found = described_class.new(user.id.to_s).execute!
expect { finder.find_by_username! }.to raise_error(ActiveRecord::RecordNotFound)
expect(found).to eq(user)
end
end
end
end
context 'when passing an existing id (as string) to the username' do
context 'when the user exists (username)' do
it 'raises ActiveRecord::RecordNotFound' do
it 'returns the user' do
finder = described_class.new(user.id.to_s)
found = described_class.new(user.username).execute!
expect { finder.find_by_username! }.to raise_error(ActiveRecord::RecordNotFound)
expect(found).to eq(user)
end
end
end
end
Loading