show_spec.rb 4.9 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Group show page' do
4 5 6 7
  let(:group) { create(:group) }
  let(:path) { group_path(group) }

  context 'when signed in' do
8 9 10 11
    let(:user) do
      create(:group_member, :developer, user: create(:user), group: group ).user
    end

12
    before do
13
      sign_in(user)
14 15 16
      visit path
    end

17
    it_behaves_like "an autodiscoverable RSS feed with current_user's feed token"
18 19 20 21 22 23

    context 'when group does not exist' do
      let(:path) { group_path('not-exist') }

      it { expect(status_code).to eq(404) }
    end
24 25 26
  end

  context 'when signed out' do
27 28 29 30 31
    describe 'RSS' do
      before do
        visit path
      end

32
      it_behaves_like "an autodiscoverable RSS feed without a feed token"
33 34
    end

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    context 'when group has a public project', :js do
      let!(:project) { create(:project, :public, namespace: group) }

      it 'renders public project' do
        visit path

        expect(page).to have_link group.name
        expect(page).to have_link project.name
      end
    end

    context 'when group has a private project', :js do
      let!(:project) { create(:project, :private, namespace: group) }

      it 'does not render private project' do
        visit path

        expect(page).to have_link group.name
        expect(page).not_to have_link project.name
      end
    end
56
  end
57 58

  context 'subgroup support' do
59 60
    let(:owner) { create(:user) }
    let(:maintainer) { create(:user) }
61 62

    before do
63 64
      group.add_owner(owner)
      group.add_maintainer(maintainer)
65
    end
66

67
    context 'for owners' do
68
      before do
69 70 71 72 73 74 75 76 77
        sign_in(owner)
      end

      context 'when subgroups are supported', :js, :nested_groups do
        before do
          allow(Group).to receive(:supports_nested_objects?) { true }
        end

        it 'allows creating subgroups' do
78 79
          visit path

F
Fabio Papa 已提交
80 81
          expect(page)
            .to have_css("li[data-text='New subgroup']", visible: false)
82
        end
83 84
      end

85 86 87 88 89
      context 'when subgroups are not supported' do
        before do
          allow(Group).to receive(:supports_nested_objects?) { false }
        end

90
        it 'does not allow creating subgroups' do
91 92
          visit path

F
Fabio Papa 已提交
93 94
          expect(page)
            .not_to have_selector("li[data-text='New subgroup']", visible: false)
95
        end
96 97 98
      end
    end

99
    context 'for maintainers' do
100
      before do
101 102 103 104 105 106 107 108
        sign_in(maintainer)
      end

      context 'when subgroups are supported', :js, :nested_groups do
        before do
          allow(Group).to receive(:supports_nested_objects?) { true }
        end

109
        context 'when subgroup_creation_level is set to maintainers' do
F
Fabio Papa 已提交
110 111 112 113 114
          let(:group) do
            create(:group,
                   subgroup_creation_level: ::Gitlab::Access::MAINTAINER_SUBGROUP_ACCESS)
          end

115 116
          it 'allows creating subgroups' do
            visit path
117 118 119

            expect(page)
              .to have_css("li[data-text='New subgroup']", visible: false)
120 121 122 123
          end
        end

        context 'when subgroup_creation_level is set to owners' do
F
Fabio Papa 已提交
124 125 126 127
          let(:group) do
            create(:group,
                   subgroup_creation_level: ::Gitlab::Access::OWNER_SUBGROUP_ACCESS)
          end
128 129 130

          it 'does not allow creating subgroups' do
            visit path
131

F
Fabio Papa 已提交
132 133
            expect(page)
              .not_to have_css("li[data-text='New subgroup']", visible: false)
134
          end
135
        end
136 137
      end

138 139 140 141 142
      context 'when subgroups are not supported' do
        before do
          allow(Group).to receive(:supports_nested_objects?) { false }
        end

143
        it 'does not allow creating subgroups' do
144 145
          visit path

F
Fabio Papa 已提交
146 147
          expect(page)
            .not_to have_selector("li[data-text='New subgroup']", visible: false)
148
        end
149 150 151
      end
    end
  end
J
Jacopo 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164

  context 'group has a project with emoji in description', :js do
    let(:user) { create(:user) }
    let!(:project) { create(:project, description: ':smile:', namespace: group) }

    before do
      group.add_owner(user)
      sign_in(user)
      visit path
    end

    it 'shows the project info' do
      expect(page).to have_content(project.title)
B
Bob Van Landuyt 已提交
165
      expect(page).to have_emoji('smile')
J
Jacopo 已提交
166 167
    end
  end
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

  context 'where group has projects' do
    let(:user) { create(:user) }

    before do
      group.add_owner(user)
      sign_in(user)
    end

    it 'allows users to sorts projects by most stars', :js do
      project1 = create(:project, namespace: group, star_count: 2)
      project2 = create(:project, namespace: group, star_count: 3)
      project3 = create(:project, namespace: group, star_count: 0)

      visit group_path(group, sort: :stars_desc)

      expect(find('.group-row:nth-child(1) .namespace-title > a')).to have_content(project2.title)
      expect(find('.group-row:nth-child(2) .namespace-title > a')).to have_content(project1.title)
      expect(find('.group-row:nth-child(3) .namespace-title > a')).to have_content(project3.title)
    end
  end
189
end