diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-18 12:07:48 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-18 12:07:48 +0000 |
commit | 79d62647bcfad69d7272020acb7d8be5ee5df003 (patch) | |
tree | 008d96a4c5fdfdecda79dae5e942c7df07511c77 /spec/models | |
parent | 1a9d9cc14ec54036548824e3ce17da03960f5f81 (diff) | |
download | gitlab-ce-79d62647bcfad69d7272020acb7d8be5ee5df003.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/ci/build_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/diff_note_spec.rb | 120 |
2 files changed, 127 insertions, 11 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 900e0feaccc..20915e6d3b1 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2245,14 +2245,24 @@ describe Ci::Build do end end - describe '#has_expiring_artifacts?' do + describe '#has_expiring_archive_artifacts?' do context 'when artifacts have expiration date set' do before do build.update(artifacts_expire_at: 1.day.from_now) end - it 'has expiring artifacts' do - expect(build).to have_expiring_artifacts + context 'and job artifacts file exists' do + let!(:archive) { create(:ci_job_artifact, :archive, job: build) } + + it 'has expiring artifacts' do + expect(build).to have_expiring_archive_artifacts + end + end + + context 'and job artifacts file does not exist' do + it 'does not have expiring artifacts' do + expect(build).not_to have_expiring_archive_artifacts + end end end @@ -2262,7 +2272,7 @@ describe Ci::Build do end it 'does not have expiring artifacts' do - expect(build).not_to have_expiring_artifacts + expect(build).not_to have_expiring_archive_artifacts end end end diff --git a/spec/models/diff_note_spec.rb b/spec/models/diff_note_spec.rb index 601dac21e6a..ae493d5c081 100644 --- a/spec/models/diff_note_spec.rb +++ b/spec/models/diff_note_spec.rb @@ -91,18 +91,124 @@ describe DiffNote do end describe '#create_diff_file callback' do - let(:noteable) { create(:merge_request) } - let(:project) { noteable.project } - context 'merge request' do - let!(:diff_note) { create(:diff_note_on_merge_request, project: project, noteable: noteable) } + 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 - it 'creates a diff note file' do - expect(diff_note.reload.note_diff_file).to be_present + 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' end it 'does not create diff note file if it is a reply' do - expect { create(:diff_note_on_merge_request, noteable: noteable, in_reply_to: diff_note) } + 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) } .not_to change(NoteDiffFile, :count) end end |