summaryrefslogtreecommitdiff
path: root/spec/views/help/index.html.haml_spec.rb
blob: 3831ddacb72d66179920ff3130294c69e0559346 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# frozen_string_literal: true

require 'spec_helper'

describe 'help/index' do
  include StubVersion

  describe 'version information' do
    before do
      stub_helpers
    end

    it 'is hidden from guests' do
      stub_user(nil)
      stub_version('8.0.2', 'abcdefg')

      render

      expect(rendered).not_to match '8.0.2'
      expect(rendered).not_to match 'abcdefg'
    end

    context 'when logged in' do
      before do
        stub_user
      end

      it 'shows a link to the tag to users' do
        stub_version('8.0.2', 'abcdefg')

        render

        expect(rendered).to match '8.0.2'
        expect(rendered).to have_link('8.0.2', href: %r{https://gitlab.com/gitlab-org/(gitlab|gitlab-foss)/-/tags/v8.0.2})
      end

      it 'shows a link to the commit for pre-releases' do
        stub_version('8.0.2-pre', 'abcdefg')

        render

        expect(rendered).to match '8.0.2'
        expect(rendered).to have_link('abcdefg', href: %r{https://gitlab.com/gitlab-org/(gitlab|gitlab-foss)/-/commits/abcdefg})
      end
    end
  end

  describe 'instance configuration link' do
    it 'is visible to guests' do
      render

      expect(rendered).to have_link(nil, href: help_instance_configuration_url)
    end
  end

  describe 'Markdown rendering' do
    before do
      assign(:help_index, 'Welcome to [GitLab](https://about.gitlab.com/) Documentation.')
    end

    it 'renders Markdown' do
      render

      expect(rendered).to have_link('GitLab', href: 'https://about.gitlab.com/')
    end
  end

  def stub_user(user = double)
    allow(view).to receive(:user_signed_in?).and_return(user)
  end

  def stub_helpers
    allow(view).to receive(:markdown).and_return('')
    allow(view).to receive(:version_status_badge).and_return('')
    allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings)
  end
end