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 @@
describe UserFinder do
set(:user) { create(:user) }
describe '#execute' do
context 'when the user exists (id)' do
describe '#find_by_id' do
context 'when the user exists' 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)
end
@@ -16,57 +16,61 @@
context 'when the user exists (id as string)' 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)
end
end
context 'when the user exists (username)' do
it 'returns the user' do
found = described_class.new(user.username).execute
context 'when the user does not exist' do
it 'returns nil' do
found = described_class.new(1).find_by_id
expect(found).to eq(user)
expect(found).to be_nil
end
end
end
context 'when passing a non existing username to the id' do
it 'returns nil' do
found = described_class.new("non_existent_username").find_by_id
describe '#find_by_username' do
context 'when the user exists' do
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
context 'when passing an existing username to the id' do
context 'when the user does not exist' 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
end
end
end
context 'when passing a non existing id to the username' do
it 'returns nil' do
found = described_class.new(1).find_by_username
describe '#execute' do
context 'when the user exists (id)' do
it 'returns the user' do
found = described_class.new(user.id).execute
expect(found).to be_nil
expect(found).to eq(user)
end
end
context 'when passing an existing id to the username' do
it 'returns nil' do
found = described_class.new(user.id).find_by_username
context 'when the user exists (id as string)' do
it 'returns the user' do
found = described_class.new(user.id.to_s).execute
expect(found).to be_nil
expect(found).to eq(user)
end
end
context 'when passing an existing id (as string) to the username' do
it 'returns nil' do
found = described_class.new(user.id.to_s).find_by_username
context 'when the user exists (username)' do
it 'returns the user' do
found = described_class.new(user.username).execute
expect(found).to be_nil
expect(found).to eq(user)
end
end
@@ -87,10 +91,10 @@
end
end
describe '#execute!' do
context 'when the user exists (id)' do
describe '#find_by_id!' do
context 'when the user exists' 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)
end
@@ -98,57 +102,61 @@
context 'when the user exists (id as string)' 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)
end
end
context 'when the user exists (username)' do
it 'returns the user' do
found = described_class.new(user.username).execute!
context 'when the user does not exist' do
it 'raises ActiveRecord::RecordNotFound' do
finder = described_class.new(1)
expect(found).to eq(user)
expect { finder.find_by_id! }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
context 'when passing a non existing username to the id' do
it 'raises ActiveRecord::RecordNotFound' do
finder = described_class.new("non_existent_username")
describe '#find_by_username!' do
context 'when the user exists' do
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
context 'when passing an existing username to the id' do
context 'when the user does not exist' 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
context 'when passing a non existing id to the username' do
it 'raises ActiveRecord::RecordNotFound' do
finder = described_class.new(1)
describe '#execute!' do
context 'when the user exists (id)' do
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
context 'when passing an existing id to the username' do
it 'raises ActiveRecord::RecordNotFound' do
finder = described_class.new(user.id)
context 'when the user exists (id as string)' do
it 'returns the user' do
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
context 'when passing an existing id (as string) to the username' do
it 'raises ActiveRecord::RecordNotFound' do
finder = described_class.new(user.id.to_s)
context 'when the user exists (username)' do
it 'returns the user' do
found = described_class.new(user.username).execute!
expect { finder.find_by_username! }.to raise_error(ActiveRecord::RecordNotFound)
expect(found).to eq(user)
end
end
Loading