Commit 8fea7c73 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Set new MR diff as latest even when importing

These are already set when `set_latest_merge_request_diff_ids!`
is called in `ProjectTreeRestorer` but we do not use this when doing
GitHub imports. So we need to do this for imports too.
parent e1e868cb
......@@ -136,7 +136,7 @@ class MergeRequestDiff < ApplicationRecord
# All diff information is collected from repository after object is created.
# It allows you to override variables like head_commit_sha before getting diff.
after_create :save_git_content, unless: :importing?
after_create_commit :set_as_latest_diff, unless: :importing?
after_create_commit :set_as_latest_diff
after_save :update_external_diff_store, if: -> { !importing? && saved_change_to_external_diff? }
......
......@@ -311,10 +311,11 @@ describe Gitlab::GithubImport::Importer::PullRequestImporter, :clean_gitlab_redi
end
end
it 'creates the merge request diffs' do
it 'creates a merge request diff and sets it as the latest' do
mr = insert_git_data
expect(mr.merge_request_diffs.exists?).to eq(true)
expect(mr.reload.latest_merge_request_diff_id).to eq(mr.merge_request_diffs.first.id)
end
it 'creates the merge request diff commits' do
......
......@@ -21,8 +21,11 @@ describe Gitlab::Import::MergeRequestCreator do
subject.execute(attributes)
expect(merge_request.reload.merge_request_diffs.count).to eq(1)
expect(merge_request.reload.merge_request_diffs.first.commits.count).to eq(commits_count)
merge_request.reload
expect(merge_request.merge_request_diffs.count).to eq(1)
expect(merge_request.merge_request_diffs.first.commits.count).to eq(commits_count)
expect(merge_request.latest_merge_request_diff_id).to eq(merge_request.merge_request_diffs.first.id)
end
end
......
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