summaryrefslogtreecommitdiff
path: root/spec/models/review_spec.rb
blob: 9dd8b90feee3b6cf431e9ca6ddec63af24931228 (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
# frozen_string_literal: true

require 'spec_helper'

describe Review do
  describe 'associations' do
    it { is_expected.to belong_to(:author).class_name('User').with_foreign_key(:author_id).inverse_of(:reviews) }
    it { is_expected.to belong_to(:merge_request).inverse_of(:reviews).touch(false) }
    it { is_expected.to belong_to(:project).inverse_of(:reviews) }

    it { is_expected.to have_many(:notes).order(:id).inverse_of(:review) }
  end

  describe 'modules' do
    it { is_expected.to include_module(Participable) }
    it { is_expected.to include_module(Mentionable) }
  end

  describe '#all_references' do
    it 'returns an extractor with the correct referenced users' do
      user1 = create(:user, username: "foo")
      user2 = create(:user, username: "bar")
      review = create(:review)
      project = review.project
      author = review.author

      create(:note, review: review, project: project, author: author, note: "cc @foo @non_existent")
      create(:note, review: review, project: project, author: author, note: "cc @bar")

      expect(review.all_references(author).users).to match_array([user1, user2])
    end
  end

  describe '#participants' do
    it 'includes the review author' do
      project = create(:project, :public)
      merge_request = create(:merge_request, source_project: project)
      review = create(:review, project: project, merge_request: merge_request)
      create(:note, review: review, noteable: merge_request, project: project, author: review.author)

      expect(review.participants).to include(review.author)
    end
  end
end