2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-01 16:53:02 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe DiffNote do
|
2016-07-01 16:53:02 -04:00
|
|
|
include RepoHelpers
|
|
|
|
|
2019-12-23 07:08:18 -05:00
|
|
|
let_it_be(:merge_request) { create(:merge_request) }
|
|
|
|
let_it_be(:project) { merge_request.project }
|
|
|
|
let_it_be(:commit) { project.commit(sample_commit.id) }
|
2016-07-01 16:53:02 -04:00
|
|
|
|
2019-12-23 07:08:18 -05:00
|
|
|
let_it_be(:path) { "files/ruby/popen.rb" }
|
2016-07-01 16:53:02 -04:00
|
|
|
|
2017-12-01 14:08:30 -05:00
|
|
|
let(:diff_refs) { merge_request.diff_refs }
|
2016-07-07 16:13:55 -04:00
|
|
|
let!(:position) do
|
2016-07-01 16:53:02 -04:00
|
|
|
Gitlab::Diff::Position.new(
|
|
|
|
old_path: path,
|
|
|
|
new_path: path,
|
|
|
|
old_line: nil,
|
|
|
|
new_line: 14,
|
2017-12-01 14:08:30 -05:00
|
|
|
diff_refs: diff_refs
|
2016-07-01 16:53:02 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2016-07-07 16:13:55 -04:00
|
|
|
let!(:new_position) do
|
2016-07-01 16:53:02 -04:00
|
|
|
Gitlab::Diff::Position.new(
|
|
|
|
old_path: path,
|
|
|
|
new_path: path,
|
|
|
|
old_line: 16,
|
|
|
|
new_line: 22,
|
2017-12-01 14:08:30 -05:00
|
|
|
diff_refs: diff_refs
|
2016-07-01 16:53:02 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { create(:diff_note_on_merge_request, project: project, position: position, noteable: merge_request) }
|
|
|
|
|
2019-07-18 08:09:35 -04:00
|
|
|
describe 'validations' do
|
2020-09-04 08:08:27 -04:00
|
|
|
it_behaves_like 'a valid diff positionable note' do
|
|
|
|
subject { build(:diff_note_on_commit, project: project, commit_id: commit_id, position: position) }
|
|
|
|
end
|
2019-07-18 08:09:35 -04:00
|
|
|
end
|
|
|
|
|
2016-07-01 16:53:02 -04:00
|
|
|
describe "#position=" do
|
|
|
|
context "when provided a string" do
|
|
|
|
it "sets the position" do
|
|
|
|
subject.position = new_position.to_json
|
|
|
|
|
|
|
|
expect(subject.position).to eq(new_position)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when provided a hash" do
|
|
|
|
it "sets the position" do
|
|
|
|
subject.position = new_position.to_h
|
|
|
|
|
|
|
|
expect(subject.position).to eq(new_position)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when provided a position object" do
|
|
|
|
it "sets the position" do
|
|
|
|
subject.position = new_position
|
|
|
|
|
|
|
|
expect(subject.position).to eq(new_position)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-09 20:29:11 -05:00
|
|
|
describe "#original_position=" do
|
2017-03-17 15:25:52 -04:00
|
|
|
context "when provided a string" do
|
|
|
|
it "sets the original position" do
|
|
|
|
subject.original_position = new_position.to_json
|
|
|
|
|
|
|
|
expect(subject.original_position).to eq(new_position)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when provided a hash" do
|
|
|
|
it "sets the original position" do
|
|
|
|
subject.original_position = new_position.to_h
|
|
|
|
|
|
|
|
expect(subject.original_position).to eq(new_position)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when provided a position object" do
|
|
|
|
it "sets the original position" do
|
|
|
|
subject.original_position = new_position
|
|
|
|
|
|
|
|
expect(subject.original_position).to eq(new_position)
|
|
|
|
end
|
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
|
|
|
|
2018-05-16 11:46:18 -04:00
|
|
|
describe '#create_diff_file callback' do
|
|
|
|
context 'merge request' do
|
2019-12-18 07:07:48 -05:00
|
|
|
let(:position) do
|
|
|
|
Gitlab::Diff::Position.new(old_path: "files/ruby/popen.rb",
|
|
|
|
new_path: "files/ruby/popen.rb",
|
|
|
|
old_line: nil,
|
|
|
|
new_line: 9,
|
|
|
|
diff_refs: merge_request.diff_refs)
|
|
|
|
end
|
2018-05-16 11:46:18 -04:00
|
|
|
|
2019-12-18 07:07:48 -05:00
|
|
|
subject { build(:diff_note_on_merge_request, project: project, position: position, noteable: merge_request) }
|
|
|
|
|
|
|
|
let(:diff_file_from_repository) do
|
|
|
|
position.diff_file(project.repository)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:diff_file) do
|
|
|
|
diffs = merge_request.diffs
|
|
|
|
raw_diff = diffs.diffable.raw_diffs(diffs.diff_options.merge(paths: ['files/ruby/popen.rb'])).first
|
|
|
|
Gitlab::Diff::File.new(raw_diff,
|
|
|
|
repository: diffs.project.repository,
|
|
|
|
diff_refs: diffs.diff_refs,
|
|
|
|
fallback_diff_refs: diffs.fallback_diff_refs)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:diff_line) { diff_file.diff_lines.first }
|
|
|
|
|
|
|
|
let(:line_code) { '2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subject.position).to receive(:line_code).and_return('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when diffs are already created' do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:created_at_diff?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when diff_file is found in persisted diffs' do
|
|
|
|
before do
|
|
|
|
allow(merge_request).to receive_message_chain(:diffs, :diff_files, :first).and_return(diff_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when importing' do
|
|
|
|
before do
|
|
|
|
subject.importing = true
|
|
|
|
subject.line_code = line_code
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when diff_line is found in persisted diff_file' do
|
|
|
|
before do
|
|
|
|
allow(diff_file).to receive(:line_for_position).with(position).and_return(diff_line)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a diff note file' do
|
|
|
|
subject.save
|
|
|
|
expect(subject.note_diff_file).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when diff_line is not found in persisted diff_file' do
|
|
|
|
before do
|
|
|
|
allow(diff_file).to receive(:line_for_position).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a valid diff note with after commit callback'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when not importing' do
|
|
|
|
context 'when diff_line is not found' do
|
|
|
|
before do
|
|
|
|
allow(diff_file).to receive(:line_for_position).with(position).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error' do
|
|
|
|
expect { subject.save }.to raise_error(::DiffNote::NoteDiffFileCreationError,
|
|
|
|
"Failed to find diff line for: #{diff_file.file_path}, "\
|
|
|
|
"old_line: #{position.old_line}"\
|
|
|
|
", new_line: #{position.new_line}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when diff_line is found' do
|
|
|
|
before do
|
|
|
|
allow(diff_file).to receive(:line_for_position).with(position).and_return(diff_line)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a diff note file' do
|
|
|
|
subject.save
|
|
|
|
expect(subject.reload.note_diff_file).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when diff file is not found in persisted diffs' do
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff) do |merge_request_diff|
|
|
|
|
allow(merge_request_diff).to receive(:diff_files).and_return([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a valid diff note with after commit callback'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when diffs are not already created' do
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:created_at_diff?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a valid diff note with after commit callback'
|
2018-05-16 11:46:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create diff note file if it is a reply' do
|
2019-12-18 07:07:48 -05:00
|
|
|
diff_note = create(:diff_note_on_merge_request, project: project, noteable: merge_request)
|
|
|
|
|
|
|
|
expect { create(:diff_note_on_merge_request, noteable: merge_request, in_reply_to: diff_note) }
|
2018-05-16 11:46:18 -04:00
|
|
|
.not_to change(NoteDiffFile, :count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'commit' do
|
|
|
|
let!(:diff_note) { create(:diff_note_on_commit, project: project) }
|
|
|
|
|
|
|
|
it 'creates a diff note file' do
|
|
|
|
expect(diff_note.reload.note_diff_file).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create diff note file if it is a reply' do
|
|
|
|
expect { create(:diff_note_on_commit, in_reply_to: diff_note) }
|
|
|
|
.not_to change(NoteDiffFile, :count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#diff_file', :clean_gitlab_redis_shared_state do
|
|
|
|
context 'when note_diff_file association exists' do
|
|
|
|
it 'returns persisted diff file data' do
|
|
|
|
diff_file = subject.diff_file
|
|
|
|
|
|
|
|
expect(diff_file.diff.to_hash.with_indifferent_access)
|
|
|
|
.to include(subject.note_diff_file.to_hash)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-30 17:44:37 -04:00
|
|
|
context 'when the discussion was created in the diff' do
|
2020-06-05 17:08:27 -04:00
|
|
|
context 'when file_identifier_hash is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(file_identifier_hash: false)
|
|
|
|
end
|
2016-07-01 16:53:02 -04:00
|
|
|
|
2020-06-05 17:08:27 -04:00
|
|
|
it 'returns correct diff file' do
|
|
|
|
diff_file = subject.diff_file
|
|
|
|
|
|
|
|
expect(diff_file.old_path).to eq(position.old_path)
|
|
|
|
expect(diff_file.new_path).to eq(position.new_path)
|
|
|
|
expect(diff_file.diff_refs).to eq(position.diff_refs)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when file_identifier_hash is enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(file_identifier_hash: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct diff file' do
|
|
|
|
diff_file = subject.diff_file
|
|
|
|
|
|
|
|
expect(diff_file.old_path).to eq(position.old_path)
|
|
|
|
expect(diff_file.new_path).to eq(position.new_path)
|
|
|
|
expect(diff_file.diff_refs).to eq(position.diff_refs)
|
|
|
|
end
|
2018-04-30 17:44:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when discussion is outdated or not created in the diff' do
|
|
|
|
let(:diff_refs) { project.commit(sample_commit.id).diff_refs }
|
|
|
|
let(:position) do
|
|
|
|
Gitlab::Diff::Position.new(
|
|
|
|
old_path: "files/ruby/popen.rb",
|
|
|
|
new_path: "files/ruby/popen.rb",
|
|
|
|
old_line: nil,
|
|
|
|
new_line: 14,
|
|
|
|
diff_refs: diff_refs
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the correct diff file' do
|
|
|
|
diff_file = subject.diff_file
|
|
|
|
|
|
|
|
expect(diff_file.old_path).to eq(position.old_path)
|
|
|
|
expect(diff_file.new_path).to eq(position.new_path)
|
|
|
|
expect(diff_file.diff_refs).to eq(position.diff_refs)
|
|
|
|
end
|
2016-07-01 16:53:02 -04:00
|
|
|
end
|
2018-05-16 11:46:18 -04:00
|
|
|
|
|
|
|
context 'note diff file creation enqueuing' do
|
|
|
|
it 'enqueues CreateNoteDiffFileWorker if it is the first note of a discussion' do
|
|
|
|
subject.note_diff_file.destroy!
|
|
|
|
|
|
|
|
expect(CreateNoteDiffFileWorker).to receive(:perform_async).with(subject.id)
|
|
|
|
|
|
|
|
subject.reload.diff_file
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not enqueues CreateNoteDiffFileWorker if not first note of a discussion' do
|
|
|
|
mr = create(:merge_request)
|
|
|
|
diff_note = create(:diff_note_on_merge_request, project: mr.project, noteable: mr)
|
|
|
|
reply_diff_note = create(:diff_note_on_merge_request, in_reply_to: diff_note)
|
|
|
|
|
|
|
|
expect(CreateNoteDiffFileWorker).not_to receive(:perform_async).with(reply_diff_note.id)
|
|
|
|
|
|
|
|
reply_diff_note.reload.diff_file
|
|
|
|
end
|
|
|
|
end
|
2020-05-04 02:10:10 -04:00
|
|
|
|
|
|
|
context 'when noteable is a Design' do
|
|
|
|
it 'does not return a diff file' do
|
|
|
|
diff_note = create(:diff_note_on_design)
|
|
|
|
|
|
|
|
expect(diff_note.diff_file).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#latest_diff_file' do
|
|
|
|
context 'when noteable is a Design' do
|
|
|
|
it 'does not return a diff file' do
|
|
|
|
diff_note = create(:diff_note_on_design)
|
|
|
|
|
|
|
|
expect(diff_note.latest_diff_file).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-07-01 16:53:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#diff_line" do
|
|
|
|
it "returns the correct diff line" do
|
|
|
|
diff_line = subject.diff_line
|
|
|
|
|
|
|
|
expect(diff_line.added?).to be true
|
2017-10-07 00:25:17 -04:00
|
|
|
expect(diff_line.new_line).to eq(position.formatter.new_line)
|
2016-07-01 16:53:02 -04:00
|
|
|
expect(diff_line.text).to eq("+ vars = {")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#line_code" do
|
|
|
|
it "returns the correct line code" do
|
2017-10-10 13:44:14 -04:00
|
|
|
line_code = Gitlab::Git.diff_line_code(position.file_path, position.formatter.new_line, 15)
|
2016-07-01 16:53:02 -04:00
|
|
|
|
|
|
|
expect(subject.line_code).to eq(line_code)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#active?" do
|
|
|
|
context "when noteable is a commit" do
|
2016-08-15 19:45:23 -04:00
|
|
|
subject { build(:diff_note_on_commit, project: project, position: position) }
|
2016-07-01 16:53:02 -04:00
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.active?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when noteable is a merge request" do
|
|
|
|
context "when the merge request's diff refs match that of the diff note" do
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.active?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the merge request's diff refs don't match that of the diff note" do
|
|
|
|
before do
|
2017-05-15 14:19:49 -04:00
|
|
|
allow(subject.noteable).to receive(:diff_refs).and_return(commit.diff_refs)
|
2016-07-01 16:53:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.active?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-07 16:13:55 -04:00
|
|
|
describe "creation" do
|
|
|
|
describe "updating of position" do
|
|
|
|
context "when noteable is a commit" do
|
2017-12-01 14:08:30 -05:00
|
|
|
let(:diff_refs) { commit.diff_refs }
|
2016-07-01 16:53:02 -04:00
|
|
|
|
2017-12-01 14:08:30 -05:00
|
|
|
subject { create(:diff_note_on_commit, project: project, position: position, commit_id: commit.id) }
|
2016-07-01 16:53:02 -04:00
|
|
|
|
2017-12-01 14:08:30 -05:00
|
|
|
it "doesn't update the position" do
|
|
|
|
is_expected.to have_attributes(original_position: position,
|
|
|
|
position: position)
|
2016-07-01 16:53:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-07 16:13:55 -04:00
|
|
|
context "when noteable is a merge request" do
|
|
|
|
context "when the note is active" do
|
|
|
|
it "doesn't update the position" do
|
2017-12-01 14:08:30 -05:00
|
|
|
expect(subject.original_position).to eq(position)
|
|
|
|
expect(subject.position).to eq(position)
|
2016-07-07 16:13:55 -04:00
|
|
|
end
|
2016-07-01 16:53:02 -04:00
|
|
|
end
|
|
|
|
|
2016-07-07 16:13:55 -04:00
|
|
|
context "when the note is outdated" do
|
|
|
|
before do
|
2017-05-15 14:19:49 -04:00
|
|
|
allow(merge_request).to receive(:diff_refs).and_return(commit.diff_refs)
|
2016-07-07 16:13:55 -04:00
|
|
|
end
|
|
|
|
|
2017-05-31 15:31:33 -04:00
|
|
|
it "updates the position" do
|
2017-12-01 14:08:30 -05:00
|
|
|
expect(subject.original_position).to eq(position)
|
|
|
|
expect(subject.position).not_to eq(position)
|
2016-07-07 16:13:55 -04:00
|
|
|
end
|
2016-07-01 16:53:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-12 01:16:38 -04:00
|
|
|
|
2016-08-17 13:14:44 -04:00
|
|
|
describe "#discussion_id" do
|
|
|
|
let(:note) { create(:diff_note_on_merge_request) }
|
|
|
|
|
|
|
|
context "when it is newly created" do
|
|
|
|
it "has a discussion id" do
|
|
|
|
expect(note.discussion_id).not_to be_nil
|
|
|
|
expect(note.discussion_id).to match(/\A\h{40}\z/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when it didn't store a discussion id before" do
|
|
|
|
before do
|
|
|
|
note.update_column(:discussion_id, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a discussion id" do
|
|
|
|
# The discussion_id is set in `after_initialize`, so `reload` won't work
|
|
|
|
reloaded_note = Note.find(note.id)
|
|
|
|
|
|
|
|
expect(reloaded_note.discussion_id).not_to be_nil
|
|
|
|
expect(reloaded_note.discussion_id).to match(/\A\h{40}\z/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-30 16:32:09 -04:00
|
|
|
|
|
|
|
describe '#created_at_diff?' do
|
|
|
|
let(:diff_refs) { project.commit(sample_commit.id).diff_refs }
|
|
|
|
let(:position) do
|
|
|
|
Gitlab::Diff::Position.new(
|
|
|
|
old_path: "files/ruby/popen.rb",
|
|
|
|
new_path: "files/ruby/popen.rb",
|
|
|
|
old_line: nil,
|
|
|
|
new_line: 14,
|
|
|
|
diff_refs: diff_refs
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when noteable is a commit" do
|
|
|
|
subject { build(:diff_note_on_commit, project: project, position: position) }
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.created_at_diff?(diff_refs)).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when noteable is a merge request" do
|
|
|
|
context "when the diff refs match the original one of the diff note" do
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.created_at_diff?(diff_refs)).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the diff refs don't match the original one of the diff note" do
|
|
|
|
it "returns false" do
|
|
|
|
expect(subject.created_at_diff?(merge_request.diff_refs)).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-10-07 00:25:17 -04:00
|
|
|
|
2018-12-13 14:17:19 -05:00
|
|
|
describe '#supports_suggestion?' do
|
2019-02-19 14:29:10 -05:00
|
|
|
context 'when noteable does not exist' do
|
|
|
|
it 'returns false' do
|
|
|
|
allow(subject).to receive(:noteable) { nil }
|
|
|
|
|
|
|
|
expect(subject.supports_suggestion?).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 14:17:19 -05:00
|
|
|
context 'when noteable does not support suggestions' do
|
|
|
|
it 'returns false' do
|
|
|
|
allow(subject.noteable).to receive(:supports_suggestion?) { false }
|
|
|
|
|
|
|
|
expect(subject.supports_suggestion?).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when line is not suggestible' do
|
|
|
|
it 'returns false' do
|
2019-11-20 01:06:16 -05:00
|
|
|
allow_next_instance_of(Gitlab::Diff::Line) do |instance|
|
|
|
|
allow(instance).to receive(:suggestible?) { false }
|
|
|
|
end
|
2018-12-13 14:17:19 -05:00
|
|
|
|
|
|
|
expect(subject.supports_suggestion?).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-13 09:57:05 -04:00
|
|
|
describe '#banzai_render_context' do
|
|
|
|
let(:note) { create(:diff_note_on_merge_request) }
|
|
|
|
|
|
|
|
it 'includes expected context' do
|
|
|
|
context = note.banzai_render_context(:note)
|
|
|
|
|
|
|
|
expect(context).to include(suggestions_filter_enabled: true, noteable: note.noteable, project: note.project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-07 00:25:17 -04:00
|
|
|
describe "image diff notes" do
|
2018-12-20 09:22:58 -05:00
|
|
|
subject { build(:image_diff_note_on_merge_request, project: project, noteable: merge_request) }
|
2017-10-07 00:25:17 -04:00
|
|
|
|
|
|
|
describe "validations" do
|
|
|
|
it { is_expected.not_to validate_presence_of(:line_code) }
|
|
|
|
|
|
|
|
it "does not validate diff line" do
|
|
|
|
diff_line = subject.diff_line
|
|
|
|
|
|
|
|
expect(diff_line).to be nil
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
2017-11-13 13:38:15 -05:00
|
|
|
|
|
|
|
it "does not update the position" do
|
|
|
|
expect(subject).not_to receive(:update_position)
|
|
|
|
|
|
|
|
subject.save
|
|
|
|
end
|
2017-10-07 00:25:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true for on_image?" do
|
|
|
|
expect(subject.on_image?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2016-07-01 16:53:02 -04:00
|
|
|
end
|