debian-mirror-gitlab/spec/models/preloaders/merge_request_diff_preloader_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
972 B
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Preloaders::MergeRequestDiffPreloader do
let_it_be(:merge_request_1) { create(:merge_request) }
let_it_be(:merge_request_2) { create(:merge_request) }
let_it_be(:merge_request_3) { create(:merge_request_without_merge_request_diff) }
let(:merge_requests) { [merge_request_1, merge_request_2, merge_request_3] }
def trigger(merge_requests)
Array(merge_requests).each(&:merge_request_diff)
end
def merge_requests_with_preloaded_diff
described_class.new(MergeRequest.where(id: merge_requests.map(&:id)).to_a).preload_all
end
it 'does not trigger N+1 queries' do
# warmup
trigger(merge_requests_with_preloaded_diff)
first_merge_request = merge_requests_with_preloaded_diff.first
clean_merge_requests = merge_requests_with_preloaded_diff
expect { trigger(clean_merge_requests) }.to issue_same_number_of_queries_as { trigger(first_merge_request) }
end
end