summaryrefslogtreecommitdiff
path: root/spec/features/dashboard/instance_statistics_spec.rb
blob: 21ee2796bd87b6888541cd3fdb1c7abded0da74a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
# frozen_string_literal: true

require 'spec_helper'

describe 'Showing instance statistics' do
  before do
    sign_in user if user
  end

  # Using a path that is publicly accessible
  subject { visit explore_projects_path }

  context 'for unauthenticated users' do
    let(:user) { nil }

    it 'does not show the instance statistics link' do
      subject

      expect(page).not_to have_link('Instance Statistics')
    end
  end

  context 'for regular users' do
    let(:user) { create(:user) }

    context 'when instance statistics are publicly available' do
      before do
        stub_application_setting(instance_statistics_visibility_private: false)
      end

      it 'shows the instance statistics link' do
        subject

        expect(page).to have_link('Instance Statistics')
      end
    end

    context 'when instance statistics are not publicly available' do
      before do
        stub_application_setting(instance_statistics_visibility_private: true)
      end

      it 'shows the instance statistics link' do
        subject

        expect(page).not_to have_link('Instance Statistics')
      end
    end
  end

  context 'for admins' do
    let(:user) { create(:admin) }

    it 'shows the instance statistics link' do
      subject

      expect(page).to have_link('Instance Statistics')
    end
  end
end