2020-04-14 11:09:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe DiffNotePosition, type: :model do
|
2020-04-15 08:09:18 -04:00
|
|
|
describe '.create_or_update_by' do
|
|
|
|
context 'when a diff note' do
|
|
|
|
let(:note) { create(:diff_note_on_merge_request) }
|
|
|
|
let(:diff_position) { build(:diff_position) }
|
|
|
|
let(:line_code) { 'bd4b7bfff3a247ccf6e3371c41ec018a55230bcc_534_521' }
|
|
|
|
let(:diff_note_position) { note.diff_note_positions.first }
|
|
|
|
let(:params) { { diff_type: :head, line_code: line_code, position: diff_position } }
|
|
|
|
|
|
|
|
context 'does not have a diff note position' do
|
|
|
|
it 'creates a diff note position' do
|
|
|
|
described_class.create_or_update_for(note, params)
|
|
|
|
|
|
|
|
expect(diff_note_position.position).to eq(diff_position)
|
|
|
|
expect(diff_note_position.line_code).to eq(line_code)
|
|
|
|
expect(diff_note_position.diff_content_type).to eq('text')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'has a diff note position' do
|
|
|
|
it 'updates the existing diff note position' do
|
|
|
|
create(:diff_note_position, note: note)
|
|
|
|
described_class.create_or_update_for(note, params)
|
|
|
|
|
|
|
|
expect(note.diff_note_positions.size).to eq(1)
|
|
|
|
expect(diff_note_position.position).to eq(diff_position)
|
|
|
|
expect(diff_note_position.line_code).to eq(line_code)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-14 11:09:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'unique by note_id and diff type' do
|
|
|
|
existing_diff_note_position = create(:diff_note_position)
|
|
|
|
diff_note_position = build(:diff_note_position, note: existing_diff_note_position.note)
|
|
|
|
|
|
|
|
expect { diff_note_position.save! }.to raise_error(ActiveRecord::RecordNotUnique)
|
|
|
|
end
|
2020-04-16 05:09:37 -04:00
|
|
|
|
|
|
|
it 'accepts a line_range attribute' do
|
|
|
|
diff_note_position = build(:diff_note_position)
|
|
|
|
|
|
|
|
expect(diff_note_position).to respond_to(:line_range)
|
|
|
|
expect(diff_note_position).to respond_to(:line_range=)
|
|
|
|
end
|
2020-04-14 11:09:44 -04:00
|
|
|
end
|