Commit 94ca25c9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve merge request diff creation and update tests

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent ceff8106
......@@ -299,12 +299,8 @@ class MergeRequest < ActiveRecord::Base
def reload_diff
return unless open?
merge_request_diff = merge_request_diffs.create
old_diff_refs = self.diff_refs
merge_request_diff.reload_content
create_merge_request_diff
new_diff_refs = self.diff_refs
update_diff_notes_positions(
......
......@@ -9,7 +9,7 @@ describe MergeRequest, models: true do
it { is_expected.to belong_to(:target_project).with_foreign_key(:target_project_id).class_name('Project') }
it { is_expected.to belong_to(:source_project).with_foreign_key(:source_project_id).class_name('Project') }
it { is_expected.to belong_to(:merge_user).class_name("User") }
it { is_expected.to have_one(:merge_request_diff).dependent(:destroy) }
it { is_expected.to have_many(:merge_request_diffs).dependent(:destroy) }
end
describe 'modules' do
......@@ -134,7 +134,7 @@ describe MergeRequest, models: true do
context 'when there are MR diffs' do
it 'delegates to the MR diffs' do
merge_request.merge_request_diff = MergeRequestDiff.new
merge_request.merge_request_diffs.build
expect(merge_request.merge_request_diff).to receive(:diffs).with(options)
......@@ -654,22 +654,26 @@ describe MergeRequest, models: true do
let(:commit) { subject.project.commit(sample_commit.id) }
it "reloads the diff content" do
expect(subject.merge_request_diff).to receive(:reload_content)
it "does not change existing merge request diff" do
expect(subject.merge_request_diff).not_to receive(:reload_content)
subject.reload_diff
end
it "creates new merge request diff" do
expect { subject.reload_diff }.to change { subject.merge_request_diffs.count }.by(1)
end
it "updates diff note positions" do
old_diff_refs = subject.diff_refs
merge_request_diff = subject.merge_request_diff
# Update merge_request_diff so that #diff_refs will return commit.diff_refs
allow(merge_request_diff).to receive(:reload_content) do
merge_request_diff.base_commit_sha = commit.parent_id
merge_request_diff.start_commit_sha = commit.parent_id
merge_request_diff.head_commit_sha = commit.sha
allow(subject).to receive(:create_merge_request_diff) do
subject.merge_request_diffs.create(
importing: true,
base_commit_sha: commit.parent_id,
start_commit_sha: commit.parent_id,
head_commit_sha: commit.sha
)
end
expect(Notes::DiffPositionUpdateService).to receive(:new).with(
......@@ -679,8 +683,8 @@ describe MergeRequest, models: true do
new_diff_refs: commit.diff_refs,
paths: note.position.paths
).and_call_original
expect_any_instance_of(Notes::DiffPositionUpdateService).to receive(:execute).with(note)
expect_any_instance_of(Notes::DiffPositionUpdateService).to receive(:execute).with(note)
expect_any_instance_of(DiffNote).to receive(:save).once
subject.reload_diff
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment