summaryrefslogtreecommitdiff
path: root/spec/helpers/button_helper_spec.rb
blob: 7c6f3b101d7a7d434c4795fb979e7d9b5135e686 (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
require 'spec_helper'

describe ButtonHelper do
  describe 'http_clone_button' do
    let(:user) { create(:user) }
    let(:project) { build_stubbed(:empty_project) }
    let(:has_tooltip_class) { 'has-tooltip' }

    def element
      element = helper.http_clone_button(project)

      Nokogiri::HTML::DocumentFragment.parse(element).first_element_child
    end

    before do
      allow(helper).to receive(:current_user).and_return(user)
    end

    context 'with internal auth enabled' do
      context 'when user has a password' do
        it 'shows no tooltip' do
          expect(element.attr('class')).not_to include(has_tooltip_class)
        end
      end

      context 'when user has password automatically set' do
        let(:user) { create(:user, password_automatically_set: true) }

        it 'shows a password tooltip' do
          expect(element.attr('class')).to include(has_tooltip_class)
          expect(element.attr('data-title')).to eq('Set a password on your account to pull or push via HTTP.')
        end
      end
    end

    context 'with internal auth disabled' do
      before do
        stub_application_setting(password_authentication_enabled?: false)
      end

      context 'when user has no personal access tokens' do
        it 'has a personal access token tooltip ' do
          expect(element.attr('class')).to include(has_tooltip_class)
          expect(element.attr('data-title')).to eq('Create a personal access token on your account to pull or push via HTTP.')
        end
      end

      context 'when user has a personal access token' do
        it 'shows no tooltip' do
          create(:personal_access_token, user: user)

          expect(element.attr('class')).not_to include(has_tooltip_class)
        end
      end
    end

    context 'when user is ldap user' do
      let(:user) { create(:omniauth_user, password_automatically_set: true) }

      it 'shows no tooltip' do
        expect(element.attr('class')).not_to include(has_tooltip_class)
      end
    end
  end
end