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 )
2019-01-11 19:31:00 -05:00
stub_commonmark_sourcepos_disabled
2017-09-05 10:18:24 -04:00
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
2017-12-21 16:15:50 -05:00
markdown_description
2017-09-05 10:18:24 -04:00
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
2018-07-11 10:36:08 -04:00
object . add_maintainer ( user )
2017-09-05 10:18:24 -04:00
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-12-21 16:15:50 -05:00
let ( :description ) { 'Awesomeness' }
2017-10-05 04:38:05 -04:00
let ( :object ) do
2017-09-05 10:18:24 -04:00
create ( :group , :nested , :with_avatar ,
2017-12-21 16:15:50 -05:00
description : description )
2017-09-05 10:18:24 -04:00
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-12-21 16:15:50 -05:00
context 'emoji in description' do
let ( :description ) { ':smile:' }
it 'has the correct markdown_description' do
2019-01-11 19:31:00 -05:00
expect ( json [ :markdown_description ] ) . to eq ( '<p dir="auto"><gl-emoji title="smiling face with open mouth and smiling eyes" data-name="smile" data-unicode-version="6.0">😄</gl-emoji></p>' )
2017-12-21 16:15:50 -05:00
end
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