2019-10-16 05:07:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-23 15:33:56 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-07-30 11:45:49 -04:00
|
|
|
describe Autocomplete::UsersFinder do
|
2017-08-23 15:33:56 -04:00
|
|
|
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') }
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
let(:params) { {} }
|
|
|
|
|
2017-09-08 05:00:31 -04:00
|
|
|
let(:project) { nil }
|
|
|
|
let(:group) { nil }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-09-08 05:00:31 -04:00
|
|
|
subject { described_class.new(params: params, current_user: current_user, project: project, group: group).execute.to_a }
|
|
|
|
|
|
|
|
context 'when current_user not passed or nil' do
|
|
|
|
let(:current_user) { nil }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
it { is_expected.to match_array([]) }
|
|
|
|
end
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-09-08 05:00:31 -04:00
|
|
|
context 'when project passed' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([project.owner]) }
|
|
|
|
|
|
|
|
context 'when author_id passed' do
|
2019-04-11 23:59:09 -04:00
|
|
|
context 'and author is active' do
|
|
|
|
let(:params) { { author_id: user1.id } }
|
2017-09-08 05:00:31 -04:00
|
|
|
|
2019-04-11 23:59:09 -04:00
|
|
|
it { is_expected.to match_array([project.owner, user1]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and author is blocked' do
|
|
|
|
let(:params) { { author_id: user2.id } }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([project.owner]) }
|
|
|
|
end
|
2017-09-08 05:00:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when group passed and project not passed' do
|
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_users([user1], GroupMember::DEVELOPER)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match_array([user1]) }
|
|
|
|
end
|
|
|
|
|
2019-07-24 05:20:54 -04:00
|
|
|
context 'when passed a subgroup' do
|
2017-11-13 06:24:01 -05:00
|
|
|
let(:grandparent) { create(:group, :public) }
|
|
|
|
let(:parent) { create(:group, :public, parent: grandparent) }
|
|
|
|
let(:child) { create(:group, :public, parent: parent) }
|
|
|
|
let(:group) { parent }
|
|
|
|
|
|
|
|
let!(:grandparent_user) { create(:group_member, :developer, group: grandparent).user }
|
|
|
|
let!(:parent_user) { create(:group_member, :developer, group: parent).user }
|
|
|
|
let!(:child_user) { create(:group_member, :developer, group: child).user }
|
|
|
|
|
|
|
|
it 'includes users from parent groups as well' do
|
|
|
|
expect(subject).to match_array([grandparent_user, parent_user])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
it { is_expected.to match_array([user1, external_user, omniauth_user, current_user]) }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
context 'when filtered by search' do
|
2017-08-24 06:46:05 -04:00
|
|
|
let(:params) { { search: 'johndoe' } }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
it { is_expected.to match_array([user1]) }
|
|
|
|
end
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
context 'when filtered by skip_users' do
|
2017-08-24 06:46:05 -04:00
|
|
|
let(:params) { { skip_users: [omniauth_user.id, current_user.id] } }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
it { is_expected.to match_array([user1, external_user]) }
|
|
|
|
end
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
context 'when todos exist' do
|
|
|
|
let!(:pending_todo1) { create(:todo, user: current_user, author: user1, state: :pending) }
|
|
|
|
let!(:pending_todo2) { create(:todo, user: external_user, author: omniauth_user, state: :pending) }
|
|
|
|
let!(:done_todo1) { create(:todo, user: current_user, author: external_user, state: :done) }
|
|
|
|
let!(:done_todo2) { create(:todo, user: user1, author: external_user, state: :done) }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
context 'when filtered by todo_filter without todo_state_filter' do
|
2017-08-24 06:46:05 -04:00
|
|
|
let(:params) { { todo_filter: true } }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
it { is_expected.to match_array([]) }
|
|
|
|
end
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
context 'when filtered by todo_filter with pending todo_state_filter' do
|
2017-08-24 06:46:05 -04:00
|
|
|
let(:params) { { todo_filter: true, todo_state_filter: 'pending' } }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
it { is_expected.to match_array([user1]) }
|
|
|
|
end
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
context 'when filtered by todo_filter with done todo_state_filter' do
|
2017-08-24 06:46:05 -04:00
|
|
|
let(:params) { { todo_filter: true, todo_state_filter: 'done' } }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
it { is_expected.to match_array([external_user]) }
|
|
|
|
end
|
|
|
|
end
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
context 'when filtered by current_user' do
|
|
|
|
let(:current_user) { user2 }
|
2017-08-24 06:46:05 -04:00
|
|
|
let(:params) { { current_user: true } }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
it { is_expected.to match_array([user2, user1, external_user, omniauth_user]) }
|
|
|
|
end
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2017-08-24 05:08:00 -04:00
|
|
|
context 'when filtered by author_id' do
|
2019-04-11 23:59:09 -04:00
|
|
|
let(:params) { { author_id: user1.id } }
|
2017-08-23 15:33:56 -04:00
|
|
|
|
2019-04-11 23:59:09 -04:00
|
|
|
it { is_expected.to match_array([user1, external_user, omniauth_user, current_user]) }
|
2017-08-24 05:08:00 -04:00
|
|
|
end
|
2017-08-23 15:33:56 -04:00
|
|
|
end
|
|
|
|
end
|