2015-03-26 22:06:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AutocompleteController do
|
2017-01-25 16:44:33 -05:00
|
|
|
let!(:project) { create(:empty_project) }
|
2016-08-05 09:29:20 -04:00
|
|
|
let!(:user) { create(:user) }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2016-11-29 06:21:50 -05:00
|
|
|
context 'GET users' do
|
2016-08-05 09:29:20 -04:00
|
|
|
let!(:user2) { create(:user) }
|
|
|
|
let!(:non_member) { create(:user) }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'project members' do
|
2015-07-11 09:16:59 -04:00
|
|
|
before do
|
2016-08-05 09:29:20 -04:00
|
|
|
sign_in(user)
|
2016-11-18 07:52:39 -05:00
|
|
|
project.add_master(user)
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -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
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
let(:body) { JSON.parse(response.body) }
|
2015-07-11 09:16:59 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it { expect(body).to be_kind_of(Array) }
|
Use CTEs for nested groups and authorizations
This commit introduces the usage of Common Table Expressions (CTEs) to
efficiently retrieve nested group hierarchies, without having to rely on
the "routes" table (which is an _incredibly_ inefficient way of getting
the data). This requires a patch to ActiveRecord (found in the added
initializer) to work properly as ActiveRecord doesn't support WITH
statements properly out of the box.
Unfortunately MySQL provides no efficient way of getting nested groups.
For example, the old routes setup could easily take 5-10 seconds
depending on the amount of "routes" in a database. Providing vastly
different logic for both MySQL and PostgreSQL will negatively impact the
development process. Because of this the various nested groups related
methods return empty relations when used in combination with MySQL.
For project authorizations the logic is split up into two classes:
* Gitlab::ProjectAuthorizations::WithNestedGroups
* Gitlab::ProjectAuthorizations::WithoutNestedGroups
Both classes get the fresh project authorizations (= as they should be
in the "project_authorizations" table), including nested groups if
PostgreSQL is used. The logic of these two classes is quite different
apart from their public interface. This complicates development a bit,
but unfortunately there is no way around this.
This commit also introduces Gitlab::GroupHierarchy. This class can be
used to get the ancestors and descendants of a base relation, or both by
using a UNION. This in turn is used by methods such as:
* Namespace#ancestors
* Namespace#descendants
* User#all_expanded_groups
Again this class relies on CTEs and thus only works on PostgreSQL. The
Namespace methods will return an empty relation when MySQL is used,
while User#all_expanded_groups will return only the groups a user is a
direct member of.
Performance wise the impact is quite large. For example, on GitLab.com
Namespace#descendants used to take around 580 ms to retrieve data for a
particular user. Using CTEs we are able to reduce this down to roughly 1
millisecond, returning the exact same data.
== On The Fly Refreshing
Refreshing of authorizations on the fly (= when
users.authorized_projects_populated was not set) is removed with this
commit. This simplifies the code, and ensures any queries used for
authorizations are not mutated because they are executed in a Rails
scope (e.g. Project.visible_to_user).
This commit includes a migration to schedule refreshing authorizations
for all users, ensuring all of them have their authorizations in place.
Said migration schedules users in batches of 5000, with 5 minutes
between every batch to smear the load around a bit.
== Spec Changes
This commit also introduces some changes to various specs. For example,
some specs for ProjectTeam assumed that creating a personal project
would _not_ lead to the owner having access, which is incorrect. Because
we also no longer refresh authorizations on the fly for new users some
code had to be added to the "empty_project" factory. This chunk of code
ensures that the owner's permissions are refreshed after creating the
project, something that is normally done in Projects::CreateService.
2017-04-24 11:19:22 -04:00
|
|
|
it { expect(body.size).to eq 2 }
|
2016-08-05 09:29:20 -04:00
|
|
|
it { expect(body.map { |u| u["username"] }).to include(user.username) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with unknown project' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: 'unknown')
|
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it { expect(response).to have_http_status(404) }
|
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'group members' do
|
|
|
|
let(:group) { create(:group) }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2015-07-11 09:16:59 -04:00
|
|
|
before do
|
2016-08-05 09:29:20 -04:00
|
|
|
sign_in(user)
|
|
|
|
group.add_owner(user)
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it { expect(response).to have_http_status(404) }
|
|
|
|
end
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'non-member login for public project' do
|
|
|
|
let!(:project) { create(:project, :public) }
|
|
|
|
|
2015-07-11 09:16:59 -04:00
|
|
|
before do
|
2016-08-05 09:29:20 -04:00
|
|
|
sign_in(non_member)
|
2016-11-18 07:52:39 -05:00
|
|
|
project.add_master(user)
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
let(:body) { JSON.parse(response.body) }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with project ID' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: project.id, current_user: true)
|
|
|
|
end
|
2015-08-06 03:20:41 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it { expect(body).to be_kind_of(Array) }
|
Use CTEs for nested groups and authorizations
This commit introduces the usage of Common Table Expressions (CTEs) to
efficiently retrieve nested group hierarchies, without having to rely on
the "routes" table (which is an _incredibly_ inefficient way of getting
the data). This requires a patch to ActiveRecord (found in the added
initializer) to work properly as ActiveRecord doesn't support WITH
statements properly out of the box.
Unfortunately MySQL provides no efficient way of getting nested groups.
For example, the old routes setup could easily take 5-10 seconds
depending on the amount of "routes" in a database. Providing vastly
different logic for both MySQL and PostgreSQL will negatively impact the
development process. Because of this the various nested groups related
methods return empty relations when used in combination with MySQL.
For project authorizations the logic is split up into two classes:
* Gitlab::ProjectAuthorizations::WithNestedGroups
* Gitlab::ProjectAuthorizations::WithoutNestedGroups
Both classes get the fresh project authorizations (= as they should be
in the "project_authorizations" table), including nested groups if
PostgreSQL is used. The logic of these two classes is quite different
apart from their public interface. This complicates development a bit,
but unfortunately there is no way around this.
This commit also introduces Gitlab::GroupHierarchy. This class can be
used to get the ancestors and descendants of a base relation, or both by
using a UNION. This in turn is used by methods such as:
* Namespace#ancestors
* Namespace#descendants
* User#all_expanded_groups
Again this class relies on CTEs and thus only works on PostgreSQL. The
Namespace methods will return an empty relation when MySQL is used,
while User#all_expanded_groups will return only the groups a user is a
direct member of.
Performance wise the impact is quite large. For example, on GitLab.com
Namespace#descendants used to take around 580 ms to retrieve data for a
particular user. Using CTEs we are able to reduce this down to roughly 1
millisecond, returning the exact same data.
== On The Fly Refreshing
Refreshing of authorizations on the fly (= when
users.authorized_projects_populated was not set) is removed with this
commit. This simplifies the code, and ensures any queries used for
authorizations are not mutated because they are executed in a Rails
scope (e.g. Project.visible_to_user).
This commit includes a migration to schedule refreshing authorizations
for all users, ensuring all of them have their authorizations in place.
Said migration schedules users in batches of 5000, with 5 minutes
between every batch to smear the load around a bit.
== Spec Changes
This commit also introduces some changes to various specs. For example,
some specs for ProjectTeam assumed that creating a personal project
would _not_ lead to the owner having access, which is incorrect. Because
we also no longer refresh authorizations on the fly for new users some
code had to be added to the "empty_project" factory. This chunk of code
ensures that the owner's permissions are refreshed after creating the
project, something that is normally done in Projects::CreateService.
2017-04-24 11:19:22 -04:00
|
|
|
it { expect(body.size).to eq 3 }
|
|
|
|
it { expect(body.map { |u| u['username'] }).to include(user.username, non_member.username) }
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-08-06 03:20:41 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'all users' do
|
2015-08-06 03:20:41 -04:00
|
|
|
before do
|
2016-08-05 09:29:20 -04:00
|
|
|
sign_in(user)
|
|
|
|
get(:users)
|
2015-08-06 03:20:41 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
2015-08-06 03:20:41 -04:00
|
|
|
it { expect(body).to be_kind_of(Array) }
|
2016-08-05 09:29:20 -04:00
|
|
|
it { expect(body.size).to eq User.count }
|
2015-08-06 03:20:41 -04:00
|
|
|
end
|
|
|
|
|
2017-05-26 13:59:00 -04:00
|
|
|
context 'limited users per page' do
|
|
|
|
let(:per_page) { 2 }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
get(:users, per_page: per_page)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
|
|
|
it { expect(body).to be_kind_of(Array) }
|
|
|
|
it { expect(body.size).to eq per_page }
|
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'unauthenticated user' do
|
|
|
|
let(:public_project) { create(:project, :public) }
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with public project' do
|
|
|
|
before do
|
2016-11-18 07:52:39 -05:00
|
|
|
public_project.add_guest(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
get(:users, project_id: public_project.id)
|
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it { expect(body).to be_kind_of(Array) }
|
Use CTEs for nested groups and authorizations
This commit introduces the usage of Common Table Expressions (CTEs) to
efficiently retrieve nested group hierarchies, without having to rely on
the "routes" table (which is an _incredibly_ inefficient way of getting
the data). This requires a patch to ActiveRecord (found in the added
initializer) to work properly as ActiveRecord doesn't support WITH
statements properly out of the box.
Unfortunately MySQL provides no efficient way of getting nested groups.
For example, the old routes setup could easily take 5-10 seconds
depending on the amount of "routes" in a database. Providing vastly
different logic for both MySQL and PostgreSQL will negatively impact the
development process. Because of this the various nested groups related
methods return empty relations when used in combination with MySQL.
For project authorizations the logic is split up into two classes:
* Gitlab::ProjectAuthorizations::WithNestedGroups
* Gitlab::ProjectAuthorizations::WithoutNestedGroups
Both classes get the fresh project authorizations (= as they should be
in the "project_authorizations" table), including nested groups if
PostgreSQL is used. The logic of these two classes is quite different
apart from their public interface. This complicates development a bit,
but unfortunately there is no way around this.
This commit also introduces Gitlab::GroupHierarchy. This class can be
used to get the ancestors and descendants of a base relation, or both by
using a UNION. This in turn is used by methods such as:
* Namespace#ancestors
* Namespace#descendants
* User#all_expanded_groups
Again this class relies on CTEs and thus only works on PostgreSQL. The
Namespace methods will return an empty relation when MySQL is used,
while User#all_expanded_groups will return only the groups a user is a
direct member of.
Performance wise the impact is quite large. For example, on GitLab.com
Namespace#descendants used to take around 580 ms to retrieve data for a
particular user. Using CTEs we are able to reduce this down to roughly 1
millisecond, returning the exact same data.
== On The Fly Refreshing
Refreshing of authorizations on the fly (= when
users.authorized_projects_populated was not set) is removed with this
commit. This simplifies the code, and ensures any queries used for
authorizations are not mutated because they are executed in a Rails
scope (e.g. Project.visible_to_user).
This commit includes a migration to schedule refreshing authorizations
for all users, ensuring all of them have their authorizations in place.
Said migration schedules users in batches of 5000, with 5 minutes
between every batch to smear the load around a bit.
== Spec Changes
This commit also introduces some changes to various specs. For example,
some specs for ProjectTeam assumed that creating a personal project
would _not_ lead to the owner having access, which is incorrect. Because
we also no longer refresh authorizations on the fly for new users some
code had to be added to the "empty_project" factory. This chunk of code
ensures that the owner's permissions are refreshed after creating the
project, something that is normally done in Projects::CreateService.
2017-04-24 11:19:22 -04:00
|
|
|
it { expect(body.size).to eq 2 }
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with project' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: project.id)
|
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it { expect(response).to have_http_status(404) }
|
2015-07-10 20:36:24 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with unknown project' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: 'unknown')
|
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it { expect(response).to have_http_status(404) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with inaccessible group' do
|
|
|
|
before do
|
2016-11-18 07:52:39 -05:00
|
|
|
project.add_guest(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
get(:users, group_id: user.namespace.id)
|
|
|
|
end
|
2015-07-11 09:16:59 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it { expect(response).to have_http_status(404) }
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #users with no project' do
|
|
|
|
before do
|
|
|
|
get(:users)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(body).to be_kind_of(Array) }
|
|
|
|
it { expect(body.size).to eq 0 }
|
|
|
|
end
|
2016-11-29 04:49:43 -05:00
|
|
|
|
|
|
|
describe 'GET #users with todo filter' do
|
|
|
|
it 'gives an array of users' do
|
|
|
|
get :users, todo_filter: true
|
|
|
|
|
|
|
|
expect(response.status).to eq 200
|
|
|
|
expect(body).to be_kind_of(Array)
|
|
|
|
end
|
|
|
|
end
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'author of issuable included' do
|
2015-07-11 09:16:59 -04:00
|
|
|
before do
|
2016-08-05 09:29:20 -04:00
|
|
|
sign_in(user)
|
2015-07-11 09:16:59 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
let(:body) { JSON.parse(response.body) }
|
2015-07-11 09:16:59 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it 'includes the author' do
|
|
|
|
get(:users, author_id: non_member.id)
|
|
|
|
|
|
|
|
expect(body.first["username"]).to eq non_member.username
|
2015-07-10 20:36:24 -04:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -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
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'skip_users parameter included' do
|
|
|
|
before { sign_in(user) }
|
|
|
|
|
|
|
|
it 'skips the user IDs passed' do
|
|
|
|
get(:users, skip_users: [user, user2].map(&:id))
|
|
|
|
|
|
|
|
other_user_ids = [non_member, project.owner, project.creator].map(&:id)
|
|
|
|
response_user_ids = JSON.parse(response.body).map { |user| user['id'] }
|
|
|
|
|
|
|
|
expect(response_user_ids).to contain_exactly(*other_user_ids)
|
|
|
|
end
|
2015-07-10 20:36:24 -04:00
|
|
|
end
|
|
|
|
end
|
2016-02-09 06:02:52 -05:00
|
|
|
|
2016-11-29 06:21:50 -05:00
|
|
|
context 'GET projects' do
|
2016-08-05 09:29:20 -04:00
|
|
|
let(:authorized_project) { create(:project) }
|
|
|
|
let(:authorized_search_project) { create(:project, name: 'rugged') }
|
|
|
|
|
2016-02-09 06:02:52 -05:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
2016-11-18 07:52:39 -05:00
|
|
|
project.add_master(user)
|
2016-02-09 06:02:52 -05:00
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'authorized projects' do
|
|
|
|
before do
|
2016-11-18 07:52:39 -05:00
|
|
|
authorized_project.add_master(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(body).to be_kind_of(Array)
|
|
|
|
expect(body.size).to eq 2
|
2016-02-09 06:02:52 -05:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
expect(body.first['id']).to eq 0
|
|
|
|
expect(body.first['name_with_namespace']).to eq 'No project'
|
2016-04-06 03:37:46 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
expect(body.last['id']).to eq authorized_project.id
|
|
|
|
expect(body.last['name_with_namespace']).to eq authorized_project.name_with_namespace
|
|
|
|
end
|
|
|
|
end
|
2016-02-09 06:02:52 -05:00
|
|
|
end
|
2016-04-06 03:37:46 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'authorized projects and search' do
|
|
|
|
before do
|
2016-11-18 07:52:39 -05:00
|
|
|
authorized_project.add_master(user)
|
|
|
|
authorized_search_project.add_master(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID and search' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id, search: 'rugged')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
2016-04-06 03:37:46 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it do
|
|
|
|
expect(body).to be_kind_of(Array)
|
|
|
|
expect(body.size).to eq 2
|
|
|
|
|
|
|
|
expect(body.last['id']).to eq authorized_search_project.id
|
|
|
|
expect(body.last['name_with_namespace']).to eq authorized_search_project.name_with_namespace
|
|
|
|
end
|
|
|
|
end
|
2016-04-06 03:37:46 -04:00
|
|
|
end
|
2016-07-13 10:38:21 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'authorized projects apply limit' do
|
|
|
|
before do
|
|
|
|
authorized_project2 = create(:project)
|
|
|
|
authorized_project3 = create(:project)
|
|
|
|
|
2016-11-18 07:52:39 -05:00
|
|
|
authorized_project.add_master(user)
|
|
|
|
authorized_project2.add_master(user)
|
|
|
|
authorized_project3.add_master(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
stub_const 'MoveToProjectFinder::PAGE_SIZE', 2
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(body).to be_kind_of(Array)
|
|
|
|
expect(body.size).to eq 3 # Of a total of 4
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authorized projects with offset' do
|
|
|
|
before do
|
|
|
|
authorized_project2 = create(:project)
|
|
|
|
authorized_project3 = create(:project)
|
|
|
|
|
2016-11-18 07:52:39 -05:00
|
|
|
authorized_project.add_master(user)
|
|
|
|
authorized_project2.add_master(user)
|
|
|
|
authorized_project3.add_master(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID and offset_id' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id, offset_id: authorized_project.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:body) { JSON.parse(response.body) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(body.detect { |item| item['id'] == 0 }).to be_nil # 'No project' is not there
|
|
|
|
expect(body.detect { |item| item['id'] == authorized_project.id }).to be_nil # Offset project is not there either
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
context 'authorized projects without admin_issue ability' do
|
|
|
|
before(:each) do
|
2016-11-18 07:52:39 -05:00
|
|
|
authorized_project.add_guest(user)
|
2016-08-05 09:29:20 -04:00
|
|
|
|
|
|
|
expect(user.can?(:admin_issue, authorized_project)).to eq(false)
|
|
|
|
end
|
2016-07-13 10:38:21 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
describe 'GET #projects with project ID' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id)
|
|
|
|
end
|
2016-07-13 10:38:21 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
let(:body) { JSON.parse(response.body) }
|
2016-07-13 10:38:21 -04:00
|
|
|
|
2016-08-05 09:29:20 -04:00
|
|
|
it do
|
|
|
|
expect(body).to be_kind_of(Array)
|
|
|
|
expect(body.size).to eq 1 # 'No project'
|
|
|
|
|
|
|
|
expect(body.first['id']).to eq 0
|
|
|
|
end
|
|
|
|
end
|
2016-07-13 10:38:21 -04:00
|
|
|
end
|
|
|
|
end
|
2015-03-26 22:06:19 -04:00
|
|
|
end
|