2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe MergeRequests::ReloadDiffsService, :use_clean_rails_memory_store_caching,
|
2023-07-09 08:55:56 +05:30
|
|
|
feature_category: :code_review_workflow do
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
let(:subject) { described_class.new(merge_request, current_user) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'creates new merge request diff' do
|
|
|
|
expect { subject.execute }.to change { merge_request.merge_request_diffs.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls update_diff_discussion_positions with correct params' do
|
|
|
|
old_diff_refs = merge_request.diff_refs
|
|
|
|
new_diff = merge_request.create_merge_request_diff
|
|
|
|
new_diff_refs = merge_request.diff_refs
|
|
|
|
|
|
|
|
expect(merge_request).to receive(:create_merge_request_diff).and_return(new_diff)
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(merge_request).to receive(:update_diff_discussion_positions).with(
|
|
|
|
old_diff_refs: old_diff_refs, new_diff_refs: new_diff_refs, current_user: current_user
|
|
|
|
)
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
subject.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change existing merge request diff' do
|
|
|
|
expect(merge_request.merge_request_diff).not_to receive(:save_git_content)
|
|
|
|
|
|
|
|
subject.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'cache clearing' do
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'clears the cache for older diffs on the merge request' do
|
2023-05-12 17:06:39 +05:30
|
|
|
expect_next_instance_of(Gitlab::Diff::FileCollection::MergeRequestDiff) do |instance|
|
|
|
|
expect(instance).to receive(:clear_cache).and_call_original
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
subject.execute
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
it 'avoids N+1 queries', :request_store do
|
|
|
|
current_user
|
|
|
|
merge_request
|
|
|
|
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new do
|
|
|
|
subject.execute
|
|
|
|
end.count
|
|
|
|
|
|
|
|
expect { subject.execute }.not_to exceed_query_limit(control_count)
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|