events_helper_spec.rb 3.61 KB
Newer Older
1 2 3
require 'spec_helper'

describe EventsHelper do
4
  describe '#event_commit_title' do
5
    let(:message) { 'foo & bar ' + 'A' * 70 + '\n' + 'B' * 80 }
6 7
    subject { helper.event_commit_title(message) }

8
    it 'returns the first line, truncated to 70 chars' do
9 10 11
      is_expected.to eq(message[0..66] + "...")
    end

12
    it 'is not html-safe' do
13 14 15
      is_expected.not_to be_a(ActiveSupport::SafeBuffer)
    end

16
    it 'handles empty strings' do
17 18
      expect(helper.event_commit_title("")).to eq("")
    end
19 20 21 22

    it 'handles nil values' do
      expect(helper.event_commit_title(nil)).to eq('')
    end
23 24

    it 'does not escape HTML entities' do
25
      expect(helper.event_commit_title('foo & bar')).to eq('foo & bar')
26
    end
27
  end
28 29 30 31 32

  describe '#event_feed_url' do
    let(:event) { create(:event) }
    let(:project) { create(:project, :public, :repository) }

33 34 35 36
    context 'issue' do
      before do
        event.target = create(:issue)
      end
37

38 39 40 41 42 43 44
      it 'returns the project issue url' do
        expect(helper.event_feed_url(event)).to eq(project_issue_url(event.project, event.target))
      end

      it 'contains the project issue IID link' do
        expect(helper.event_feed_title(event)).to include("##{event.target.iid}")
      end
45 46
    end

47 48 49 50 51 52 53 54
    context 'merge request' do
      before do
        event.target = create(:merge_request)
      end

      it 'returns the project merge request url' do
        expect(helper.event_feed_url(event)).to eq(project_merge_request_url(event.project, event.target))
      end
55

56 57 58
      it 'contains the project merge request IID link' do
        expect(helper.event_feed_title(event)).to include("!#{event.target.iid}")
      end
59 60
    end

61
    it 'returns project commit url' do
62 63 64 65 66
      event.target = create(:note_on_commit, project: project)

      expect(helper.event_feed_url(event)).to eq(project_commit_url(event.project, event.note_target))
    end

67
    it 'returns event note target url' do
68 69 70 71 72
      event.target = create(:note)

      expect(helper.event_feed_url(event)).to eq(event_note_target_url(event))
    end

73
    it 'returns project url' do
74 75 76 77 78 79
      event.project = project
      event.action = 1

      expect(helper.event_feed_url(event)).to eq(project_url(event.project))
    end

80
    it 'returns push event feed url' do
81 82 83 84 85 86
      event = create(:push_event)
      create(:push_event_payload, event: event, action: :pushed)

      expect(helper.event_feed_url(event)).to eq(push_event_feed_url(event))
    end
  end
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

  describe '#event_note_target_url' do
    let(:project) { create(:project, :public, :repository) }
    let(:event) { create(:event, project: project) }
    let(:project_base_url) { namespace_project_url(namespace_id: project.namespace, id: project) }

    subject { helper.event_note_target_url(event) }

    it 'returns a commit note url' do
      event.target = create(:note_on_commit, note: '+1 from me')

      expect(subject).to eq("#{project_base_url}/commit/#{event.target.commit_id}#note_#{event.target.id}")
    end

    it 'returns a project snippet note url' do
      event.target = create(:note, :on_snippet, note: 'keep going')

      expect(subject).to eq("#{project_base_url}/snippets/#{event.note_target.id}#note_#{event.target.id}")
    end

    it 'returns a project issue url' do
      event.target = create(:note_on_issue, note: 'nice work')

      expect(subject).to eq("#{project_base_url}/issues/#{event.note_target.iid}#note_#{event.target.id}")
    end

    it 'returns a merge request url' do
      event.target = create(:note_on_merge_request, note: 'LGTM!')

      expect(subject).to eq("#{project_base_url}/merge_requests/#{event.note_target.iid}#note_#{event.target.id}")
    end
  end
119
end