2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Discussion do
|
2016-09-13 17:45:13 +05:30
|
|
|
subject { described_class.new([first_note, second_note, third_note]) }
|
|
|
|
|
|
|
|
let(:first_note) { create(:diff_note_on_merge_request) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:merge_request) { first_note.noteable }
|
|
|
|
let(:second_note) { create(:diff_note_on_merge_request, in_reply_to: first_note) }
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:third_note) { create(:diff_note_on_merge_request) }
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '.build' do
|
|
|
|
it 'returns a discussion of the right type' do
|
|
|
|
discussion = described_class.build([first_note, second_note], merge_request)
|
|
|
|
expect(discussion).to be_a(DiffDiscussion)
|
|
|
|
expect(discussion.notes.count).to be(2)
|
|
|
|
expect(discussion.first_note).to be(first_note)
|
|
|
|
expect(discussion.noteable).to be(merge_request)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '.build_collection' do
|
|
|
|
it 'returns an array of discussions of the right type' do
|
|
|
|
discussions = described_class.build_collection([first_note, second_note, third_note], merge_request)
|
|
|
|
expect(discussions).to eq([
|
|
|
|
DiffDiscussion.new([first_note, second_note], merge_request),
|
|
|
|
DiffDiscussion.new([third_note], merge_request)
|
|
|
|
])
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
describe 'authorization' do
|
|
|
|
it 'delegates to the first note' do
|
|
|
|
policy = DeclarativePolicy.policy_for(instance_double(User, id: 1), subject)
|
|
|
|
|
|
|
|
expect(policy).to be_a(NotePolicy)
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|