2016-08-12 16:49:25 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Discussion, model: true do
|
|
|
|
subject { described_class.new([first_note, second_note, third_note]) }
|
|
|
|
|
2017-04-04 18:27:23 -04:00
|
|
|
let(:first_note) { create(:diff_note_on_merge_request) }
|
2017-03-17 15:25:52 -04:00
|
|
|
let(:merge_request) { first_note.noteable }
|
2017-04-04 18:27:23 -04:00
|
|
|
let(:second_note) { create(:diff_note_on_merge_request, in_reply_to: first_note) }
|
|
|
|
let(:third_note) { create(:diff_note_on_merge_request) }
|
2017-03-09 20:29:11 -05:00
|
|
|
|
|
|
|
describe '.build' do
|
2017-03-17 15:25:52 -04:00
|
|
|
it 'returns a discussion of the right type' do
|
|
|
|
discussion = described_class.build([first_note, second_note], merge_request)
|
2017-04-04 18:27:23 -04:00
|
|
|
expect(discussion).to be_a(DiffDiscussion)
|
2017-03-17 15:25:52 -04:00
|
|
|
expect(discussion.notes.count).to be(2)
|
|
|
|
expect(discussion.first_note).to be(first_note)
|
|
|
|
expect(discussion.noteable).to be(merge_request)
|
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.build_collection' do
|
2017-03-17 15:25:52 -04:00
|
|
|
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([
|
2017-04-04 18:27:23 -04:00
|
|
|
DiffDiscussion.new([first_note, second_note], merge_request),
|
|
|
|
DiffDiscussion.new([third_note], merge_request)
|
2017-03-17 15:25:52 -04:00
|
|
|
])
|
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
2016-08-12 16:49:25 -04:00
|
|
|
end
|