BigW Consortium Gitlab

mentionable_spec.rb 2.43 KB
Newer Older
1 2 3
require 'spec_helper'

describe Issue, "Mentionable" do
4
  describe '#mentioned_users' do
5 6
    let!(:user) { create(:user, username: 'stranger') }
    let!(:user2) { create(:user, username: 'john') }
7
    let!(:issue) { create(:issue, description: "#{user.to_reference} mentioned") }
8 9 10

    subject { issue.mentioned_users }

11 12
    it { is_expected.to include(user) }
    it { is_expected.not_to include(user2) }
13
  end
14 15 16 17 18 19 20 21 22 23 24 25

  describe '#create_cross_references!' do
    let(:project) { create(:project) }
    let(:author)  { double('author') }
    let(:commit)  { project.commit }
    let(:commit2) { project.commit }

    let!(:issue) do
      create(:issue, project: project, description: commit.to_reference)
    end

    it 'correctly removes already-mentioned Commits' do
26
      expect(SystemNoteService).not_to receive(:cross_reference)
27 28 29 30

      issue.create_cross_references!(project, author, [commit2])
    end
  end
31

32
  describe '#create_new_cross_references!' do
33 34 35 36 37 38 39 40 41 42
    let(:project) { create(:project) }
    let(:issues)  { create_list(:issue, 2, project: project) }

    context 'before changes are persisted' do
      it 'ignores pre-existing references' do
        issue = create_issue(description: issues[0].to_reference)

        expect(SystemNoteService).not_to receive(:cross_reference)

        issue.description = 'New description'
43
        issue.create_new_cross_references!
44 45 46 47 48 49 50 51
      end

      it 'notifies new references' do
        issue = create_issue(description: issues[0].to_reference)

        expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args)

        issue.description = issues[1].to_reference
52
        issue.create_new_cross_references!
53 54 55 56 57 58 59 60 61 62
      end
    end

    context 'after changes are persisted' do
      it 'ignores pre-existing references' do
        issue = create_issue(description: issues[0].to_reference)

        expect(SystemNoteService).not_to receive(:cross_reference)

        issue.update_attributes(description: 'New description')
63
        issue.create_new_cross_references!
64 65 66 67 68 69 70 71
      end

      it 'notifies new references' do
        issue = create_issue(description: issues[0].to_reference)

        expect(SystemNoteService).to receive(:cross_reference).with(issues[1], any_args)

        issue.update_attributes(description: issues[1].to_reference)
72
        issue.create_new_cross_references!
73 74 75 76 77 78 79
      end
    end

    def create_issue(description:)
      create(:issue, project: project, description: description)
    end
  end
80
end