BigW Consortium Gitlab

groups_helper_spec.rb 2.9 KB
Newer Older
Dmitriy Zaporozhets committed
1 2 3
require 'spec_helper'

describe GroupsHelper do
Michael Kozono committed
4 5
  include ApplicationHelper

Dmitriy Zaporozhets committed
6
  describe 'group_icon' do
7
    avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif')
Dmitriy Zaporozhets committed
8

9
    it 'returns an url for the avatar' do
Dmitriy Zaporozhets committed
10
      group = create(:group)
11
      group.avatar = fixture_file_upload(avatar_file_path)
Dmitriy Zaporozhets committed
12
      group.save!
13
      expect(group_icon(group.path).to_s)
14
        .to match("/uploads/-/system/group/avatar/#{group.id}/banana_sample.gif")
Dmitriy Zaporozhets committed
15 16
    end

17
    it 'gives default avatar_icon when no avatar is present' do
Dmitriy Zaporozhets committed
18 19 20 21 22
      group = create(:group)
      group.save!
      expect(group_icon(group.path)).to match('group_avatar.png')
    end
  end
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

  describe 'group_lfs_status' do
    let(:group) { create(:group) }
    let!(:project) { create(:empty_project, namespace_id: group.id) }

    before do
      allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
    end

    context 'only one project in group' do
      before do
        group.update_attribute(:lfs_enabled, true)
      end

      it 'returns all projects as enabled' do
        expect(group_lfs_status(group)).to include('Enabled for all projects')
      end

      it 'returns all projects as disabled' do
        project.update_attribute(:lfs_enabled, false)

        expect(group_lfs_status(group)).to include('Enabled for 0 out of 1 project')
      end
    end

    context 'more than one project in group' do
      before do
        create(:empty_project, namespace_id: group.id)
      end

      context 'LFS enabled in group' do
        before do
          group.update_attribute(:lfs_enabled, true)
        end

        it 'returns both projects as enabled' do
          expect(group_lfs_status(group)).to include('Enabled for all projects')
        end

        it 'returns only one as enabled' do
          project.update_attribute(:lfs_enabled, false)

          expect(group_lfs_status(group)).to include('Enabled for 1 out of 2 projects')
        end
      end

      context 'LFS disabled in group' do
        before do
          group.update_attribute(:lfs_enabled, false)
        end

        it 'returns both projects as disabled' do
          expect(group_lfs_status(group)).to include('Disabled for all projects')
        end

        it 'returns only one as disabled' do
          project.update_attribute(:lfs_enabled, true)

          expect(group_lfs_status(group)).to include('Disabled for 1 out of 2 projects')
        end
      end
    end
  end
Michael Kozono committed
86

87
  describe 'group_title', :nested_groups do
Michael Kozono committed
88 89 90 91 92 93
    let(:group) { create(:group) }
    let(:nested_group) { create(:group, parent: group) }
    let(:deep_nested_group) { create(:group, parent: nested_group) }
    let!(:very_deep_nested_group) { create(:group, parent: deep_nested_group) }

    it 'outputs the groups in the correct order' do
94
      expect(helper.group_title(very_deep_nested_group)).to match(/>#{group.name}<\/a>.*>#{nested_group.name}<\/a>.*>#{deep_nested_group.name}<\/a>/)
Michael Kozono committed
95 96
    end
  end
Dmitriy Zaporozhets committed
97
end