summaryrefslogtreecommitdiff
path: root/spec/views/events/event/_push.html.haml_spec.rb
blob: f5634de49163666e8e16a8f08d85e84c75b9b2ed (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
require 'spec_helper'

describe 'events/event/_push.html.haml' do
  let(:event) { build_stubbed(:push_event) }

  context 'with a branch' do
    let(:payload) { build_stubbed(:push_event_payload, event: event) }

    before do
      allow(event).to receive(:push_event_payload).and_return(payload)
    end

    it 'links to the branch' do
      allow(event.project.repository).to receive(:branch_exists?).with(event.ref_name).and_return(true)
      link = project_commits_path(event.project, event.ref_name)

      render partial: 'events/event/push', locals: { event: event }

      expect(rendered).to have_link(event.ref_name, href: link)
    end

    context 'that has been deleted' do
      it 'does not link to the branch' do
        render partial: 'events/event/push', locals: { event: event }

        expect(rendered).not_to have_link(event.ref_name)
      end
    end
  end

  context 'with a tag' do
    let(:payload) { build_stubbed(:push_event_payload, event: event, ref_type: :tag, ref: 'v0.1.0') }

    before do
      allow(event).to receive(:push_event_payload).and_return(payload)
    end

    it 'links to the tag' do
      allow(event.project.repository).to receive(:tag_exists?).with(event.ref_name).and_return(true)
      link = project_commits_path(event.project, event.ref_name)

      render partial: 'events/event/push', locals: { event: event }

      expect(rendered).to have_link(event.ref_name, href: link)
    end

    context 'that has been deleted' do
      it 'does not link to the tag' do
        render partial: 'events/event/push', locals: { event: event }

        expect(rendered).not_to have_link(event.ref_name)
      end
    end
  end
end