summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-15 12:09:18 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-15 12:09:18 +0000
commitb7c735c8ac11b8182807070fc6f84f2606e15427 (patch)
treee74b4d25abb8bbf23546f001dd94515e2840a3a3 /spec/models
parent221b529789f4090341a825695aeb49b8df6dd11d (diff)
downloadgitlab-ce-b7c735c8ac11b8182807070fc6f84f2606e15427.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/diff_note_position_spec.rb37
1 files changed, 29 insertions, 8 deletions
diff --git a/spec/models/diff_note_position_spec.rb b/spec/models/diff_note_position_spec.rb
index a00ba35feef..dedb8a8da4d 100644
--- a/spec/models/diff_note_position_spec.rb
+++ b/spec/models/diff_note_position_spec.rb
@@ -3,14 +3,35 @@
require 'spec_helper'
describe DiffNotePosition, type: :model do
- it 'has a position attribute' do
- diff_position = build(:diff_position)
- line_code = 'bd4b7bfff3a247ccf6e3371c41ec018a55230bcc_534_521'
- diff_note_position = build(:diff_note_position, line_code: line_code, position: diff_position)
-
- 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')
+ 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
end
it 'unique by note_id and diff type' do