diff options
author | George Andrinopoulos <geoandri@gmail.com> | 2017-05-15 13:53:12 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-05-15 13:53:12 +0000 |
commit | 872e7b7efe923192d4ef90b01672038518ba66fc (patch) | |
tree | f4dfdf553d480d0d7539f9dbd2e5bb630860a844 /spec/finders | |
parent | f5e5afc7901b646ab26130893bcbccbe5452db18 (diff) | |
download | gitlab-ce-872e7b7efe923192d4ef90b01672038518ba66fc.tar.gz |
Create a Users Finder
Diffstat (limited to 'spec/finders')
-rw-r--r-- | spec/finders/users_finder_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/finders/users_finder_spec.rb b/spec/finders/users_finder_spec.rb new file mode 100644 index 00000000000..34a5440d651 --- /dev/null +++ b/spec/finders/users_finder_spec.rb @@ -0,0 +1,66 @@ +require 'spec_helper' + +describe UsersFinder do + describe '#execute' do + let!(:user1) { create(:user, username: 'johndoe') } + let!(:user2) { create(:user, :blocked, username: 'notsorandom', ) } + let!(:external_user) { create(:user, :external) } + let!(:omniauth_user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') } + + context 'with a normal user' do + let(:user) { create(:user) } + + it 'returns all users' do + users = described_class.new(user).execute + + expect(users).to contain_exactly(user, user1, user2, omniauth_user) + end + + it 'filters by username' do + users = described_class.new(user, username: 'johndoe').execute + + expect(users).to contain_exactly(user1) + end + + it 'filters by search' do + users = described_class.new(user, search: 'orando').execute + + expect(users).to contain_exactly(user2) + end + + it 'filters by blocked users' do + users = described_class.new(user, blocked: true).execute + + expect(users).to contain_exactly(user2) + end + + it 'filters by active users' do + users = described_class.new(user, active: true).execute + + expect(users).to contain_exactly(user, user1, omniauth_user) + end + + it 'returns no external users' do + users = described_class.new(user, external: true).execute + + expect(users).to contain_exactly(user, user1, user2, omniauth_user) + end + end + + context 'with an admin user' do + let(:admin) { create(:admin) } + + it 'filters by external users' do + users = described_class.new(admin, external: true).execute + + expect(users).to contain_exactly(external_user) + end + + it 'returns all users' do + users = described_class.new(admin).execute + + expect(users).to contain_exactly(admin, user1, user2, external_user, omniauth_user) + end + end + end +end |