Commit 5a2c6881 authored by Sean McGivern's avatar Sean McGivern

Fix MR changes tab size count

This was wrong when there were over 100 files in the diff, because we
did not use the same diff options as subclasses of
`Gitlab::Diff::FileCollection::Base` when getting the raw diffs. (The
reason we don't use those classes directly is because they may perform
highlighting, which isn't needed for just counting the diffs.)
parent 8cc61d0b
......@@ -203,7 +203,11 @@ class MergeRequest < ActiveRecord::Base
end
def diff_size
opts = diff_options || {}
# The `#diffs` method ends up at an instance of a class inheriting from
# `Gitlab::Diff::FileCollection::Base`, so use those options as defaults
# here too, to get the same diff size without performing highlighting.
#
opts = Gitlab::Diff::FileCollection::Base.default_options.merge(diff_options || {})
raw_diffs(opts).size
end
......
---
title: Fix MR changes tab size count when there are over 100 files in the diff
merge_request:
author:
......@@ -209,6 +209,50 @@ describe MergeRequest, models: true do
end
end
describe '#diff_size' do
let(:merge_request) do
build(:merge_request, source_branch: 'expand-collapse-files', target_branch: 'master')
end
context 'when there are MR diffs' do
before do
merge_request.save
end
it 'returns the correct count' do
expect(merge_request.diff_size).to eq(105)
end
it 'does not perform highlighting' do
expect(Gitlab::Diff::Highlight).not_to receive(:new)
merge_request.diff_size
end
end
context 'when there are no MR diffs' do
before do
merge_request.compare = CompareService.new(
merge_request.source_project,
merge_request.source_branch
).execute(
merge_request.target_project,
merge_request.target_branch
)
end
it 'returns the correct count' do
expect(merge_request.diff_size).to eq(105)
end
it 'does not perform highlighting' do
expect(Gitlab::Diff::Highlight).not_to receive(:new)
merge_request.diff_size
end
end
end
describe "#related_notes" do
let!(:merge_request) { create(:merge_request) }
......
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