2015-03-26 22:06:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AutocompleteController do
|
|
|
|
let!(:project) { create(:project) }
|
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:user2) { create(:user) }
|
2015-08-06 03:20:41 -04:00
|
|
|
let!(:non_member) { create(:user) }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
|
|
|
context 'project members' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
2015-07-11 09:16:59 -04:00
|
|
|
describe 'GET #users with project ID' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: project.id)
|
|
|
|
end
|
|
|
|
|
2016-02-17 06:49:38 -05:00
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
2015-07-11 09:16:59 -04:00
|
|
|
it { expect(body).to be_kind_of(Array) }
|
|
|
|
it { expect(body.size).to eq 1 }
|
2016-02-22 14:39:25 -05:00
|
|
|
it { expect(body.map { |u| u["username"] }).to include(user.username) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #users with unknown project' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: 'unknown')
|
|
|
|
end
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
it { expect(response).to have_http_status(404) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'group members' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
2015-07-11 09:16:59 -04:00
|
|
|
describe 'GET #users with group ID' do
|
|
|
|
before do
|
|
|
|
get(:users, group_id: group.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(body).to be_kind_of(Array) }
|
|
|
|
it { expect(body.size).to eq 1 }
|
|
|
|
it { expect(body.first["username"]).to eq user.username }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #users with unknown group ID' do
|
|
|
|
before do
|
|
|
|
get(:users, group_id: 'unknown')
|
|
|
|
end
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
it { expect(response).to have_http_status(404) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
end
|
|
|
|
|
2015-08-06 03:20:41 -04:00
|
|
|
context 'non-member login for public project' do
|
|
|
|
let!(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(non_member)
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
|
|
|
describe 'GET #users with project ID' do
|
|
|
|
before do
|
2015-08-21 00:33:00 -04:00
|
|
|
get(:users, project_id: project.id, current_user: true)
|
2015-08-06 03:20:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(body).to be_kind_of(Array) }
|
|
|
|
it { expect(body.size).to eq 2 }
|
|
|
|
it { expect(body.map { |u| u['username'] }).to match_array([user.username, non_member.username]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-26 22:06:19 -04:00
|
|
|
context 'all users' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
get(:users)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
2015-06-13 18:24:51 -04:00
|
|
|
it { expect(body).to be_kind_of(Array) }
|
2015-05-21 17:49:06 -04:00
|
|
|
it { expect(body.size).to eq User.count }
|
2015-03-26 22:06:19 -04:00
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
|
|
|
|
context 'unauthenticated user' do
|
2015-07-11 09:16:59 -04:00
|
|
|
let(:public_project) { create(:project, :public) }
|
2015-07-10 20:36:24 -04:00
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
|
|
|
describe 'GET #users with public project' do
|
|
|
|
before do
|
2015-07-11 09:16:59 -04:00
|
|
|
public_project.team << [user, :guest]
|
|
|
|
get(:users, project_id: public_project.id)
|
2015-07-10 20:36:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(body).to be_kind_of(Array) }
|
|
|
|
it { expect(body.size).to eq 1 }
|
|
|
|
end
|
|
|
|
|
2015-07-11 09:16:59 -04:00
|
|
|
describe 'GET #users with project' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: project.id)
|
|
|
|
end
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
it { expect(response).to have_http_status(404) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #users with unknown project' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: 'unknown')
|
|
|
|
end
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
it { expect(response).to have_http_status(404) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #users with inaccessible group' do
|
|
|
|
before do
|
|
|
|
project.team << [user, :guest]
|
|
|
|
get(:users, group_id: user.namespace.id)
|
|
|
|
end
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
it { expect(response).to have_http_status(404) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2015-07-10 20:36:24 -04:00
|
|
|
describe 'GET #users with no project' do
|
|
|
|
before do
|
|
|
|
get(:users)
|
|
|
|
end
|
|
|
|
|
2015-11-19 08:49:35 -05:00
|
|
|
it { expect(body).to be_kind_of(Array) }
|
|
|
|
it { expect(body.size).to eq 0 }
|
2015-07-10 20:36:24 -04:00
|
|
|
end
|
|
|
|
end
|
2016-02-09 06:02:52 -05:00
|
|
|
|
|
|
|
context 'author of issuable included' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
2016-04-06 03:37:46 -04:00
|
|
|
it 'includes the author' do
|
|
|
|
get(:users, author_id: non_member.id)
|
|
|
|
|
2016-02-09 06:02:52 -05:00
|
|
|
expect(body.first["username"]).to eq non_member.username
|
|
|
|
end
|
2016-04-06 03:37:46 -04:00
|
|
|
|
|
|
|
it 'rejects non existent user ids' do
|
|
|
|
get(:users, author_id: 99999)
|
|
|
|
|
|
|
|
expect(body.collect { |u| u['id'] }).not_to include(99999)
|
|
|
|
end
|
2016-02-09 06:02:52 -05:00
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
end
|