2017-09-05 05:30:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe GroupChildEntity do
|
2017-10-11 08:39:23 -04:00
|
|
|
include Gitlab::Routing.url_helpers
|
|
|
|
|
2017-09-05 10:18:24 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-09-05 05:30:16 -04:00
|
|
|
let(:request) { double('request') }
|
|
|
|
let(:entity) { described_class.new(object, request: request) }
|
|
|
|
subject(:json) { entity.as_json }
|
|
|
|
|
2017-09-05 10:18:24 -04:00
|
|
|
before do
|
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'group child json' do
|
|
|
|
it 'renders json' do
|
|
|
|
is_expected.not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
%w[id
|
|
|
|
full_name
|
|
|
|
avatar_url
|
|
|
|
name
|
|
|
|
description
|
|
|
|
visibility
|
|
|
|
type
|
|
|
|
can_edit
|
|
|
|
visibility
|
2017-09-13 05:11:09 -04:00
|
|
|
permission
|
|
|
|
relative_path].each do |attribute|
|
2017-09-05 10:18:24 -04:00
|
|
|
it "includes #{attribute}" do
|
|
|
|
expect(json[attribute.to_sym]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-05 05:30:16 -04:00
|
|
|
describe 'for a project' do
|
2017-10-05 04:38:05 -04:00
|
|
|
let(:object) do
|
2017-09-05 10:18:24 -04:00
|
|
|
create(:project, :with_avatar,
|
|
|
|
description: 'Awesomeness')
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
object.add_master(user)
|
|
|
|
end
|
2017-09-05 05:30:16 -04:00
|
|
|
|
|
|
|
it 'has the correct type' do
|
|
|
|
expect(json[:type]).to eq('project')
|
|
|
|
end
|
2017-09-05 10:18:24 -04:00
|
|
|
|
|
|
|
it 'includes the star count' do
|
|
|
|
expect(json[:star_count]).to be_present
|
|
|
|
end
|
|
|
|
|
2017-10-11 08:39:23 -04:00
|
|
|
it 'has the correct edit path' do
|
|
|
|
expect(json[:edit_path]).to eq(edit_project_path(object))
|
|
|
|
end
|
|
|
|
|
2017-09-05 10:18:24 -04:00
|
|
|
it_behaves_like 'group child json'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'for a group', :nested_groups do
|
2017-10-05 04:38:05 -04:00
|
|
|
let(:object) do
|
2017-09-05 10:18:24 -04:00
|
|
|
create(:group, :nested, :with_avatar,
|
|
|
|
description: 'Awesomeness')
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
object.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the correct type' do
|
|
|
|
expect(json[:type]).to eq('group')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'counts projects and subgroups as children' do
|
|
|
|
create(:project, namespace: object)
|
|
|
|
create(:group, parent: object)
|
|
|
|
|
|
|
|
expect(json[:children_count]).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
%w[children_count leave_path parent_id number_projects_with_delimiter number_users_with_delimiter project_count subgroup_count].each do |attribute|
|
|
|
|
it "includes #{attribute}" do
|
|
|
|
expect(json[attribute.to_sym]).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-12 04:51:34 -04:00
|
|
|
it 'allows an owner to leave when there is another one' do
|
|
|
|
object.add_owner(create(:user))
|
|
|
|
|
|
|
|
expect(json[:can_leave]).to be_truthy
|
|
|
|
end
|
|
|
|
|
2017-10-11 08:39:23 -04:00
|
|
|
it 'has the correct edit path' do
|
|
|
|
expect(json[:edit_path]).to eq(edit_group_path(object))
|
|
|
|
end
|
|
|
|
|
2017-09-05 10:18:24 -04:00
|
|
|
it_behaves_like 'group child json'
|
2017-09-05 05:30:16 -04:00
|
|
|
end
|
|
|
|
end
|