BigW Consortium Gitlab

group_child_entity_spec.rb 2.29 KB
Newer Older
1 2 3
require 'spec_helper'

describe GroupChildEntity do
4 5
  include Gitlab::Routing.url_helpers

6
  let(:user) { create(:user) }
7 8 9 10
  let(:request) { double('request') }
  let(:entity) { described_class.new(object, request: request) }
  subject(:json) { entity.as_json }

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  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
29 30
       permission
       relative_path].each do |attribute|
31 32 33 34 35 36
      it "includes #{attribute}" do
        expect(json[attribute.to_sym]).to be_present
      end
    end
  end

37
  describe 'for a project' do
38
    let(:object) do
39 40 41 42 43 44 45
      create(:project, :with_avatar,
             description: 'Awesomeness')
    end

    before do
      object.add_master(user)
    end
46 47 48 49

    it 'has the correct type' do
      expect(json[:type]).to eq('project')
    end
50 51 52 53 54

    it 'includes the star count' do
      expect(json[:star_count]).to be_present
    end

55 56 57 58
    it 'has the correct edit path' do
      expect(json[:edit_path]).to eq(edit_project_path(object))
    end

59 60 61 62
    it_behaves_like 'group child json'
  end

  describe 'for a group', :nested_groups do
63
    let(:object) do
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
      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

89 90 91 92 93 94
    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

95 96 97 98
    it 'has the correct edit path' do
      expect(json[:edit_path]).to eq(edit_group_path(object))
    end

99
    it_behaves_like 'group child json'
100 101
  end
end