Commit 631f59d4 authored by Paco Guzman's avatar Paco Guzman

change the API on the merge_request_diff model from diffs -> raw_diffs

parent 6a928360
...@@ -165,7 +165,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -165,7 +165,7 @@ class MergeRequest < ActiveRecord::Base
end end
def raw_diffs(*args) def raw_diffs(*args)
merge_request_diff ? merge_request_diff.diffs(*args) : compare.raw_diffs(*args) merge_request_diff ? merge_request_diff.raw_diffs(*args) : compare.raw_diffs(*args)
end end
def diffs(diff_options = nil) def diffs(diff_options = nil)
......
...@@ -33,12 +33,12 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -33,12 +33,12 @@ class MergeRequestDiff < ActiveRecord::Base
end end
def size def size
real_size.presence || diffs.size real_size.presence || raw_diffs.size
end end
def diffs(options={}) def raw_diffs(options={})
if options[:ignore_whitespace_change] if options[:ignore_whitespace_change]
@diffs_no_whitespace ||= begin @raw_diffs_no_whitespace ||= begin
compare = Gitlab::Git::Compare.new( compare = Gitlab::Git::Compare.new(
repository.raw_repository, repository.raw_repository,
self.start_commit_sha || self.target_branch_sha, self.start_commit_sha || self.target_branch_sha,
...@@ -47,8 +47,8 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -47,8 +47,8 @@ class MergeRequestDiff < ActiveRecord::Base
compare.diffs(options) compare.diffs(options)
end end
else else
@diffs ||= {} @raw_diffs ||= {}
@diffs[options] ||= load_diffs(st_diffs, options) @raw_diffs[options] ||= load_diffs(st_diffs, options)
end end
end end
......
...@@ -10,7 +10,7 @@ describe MergeRequestDiff, models: true do ...@@ -10,7 +10,7 @@ describe MergeRequestDiff, models: true do
expect(mr_diff).not_to receive(:load_diffs) expect(mr_diff).not_to receive(:load_diffs)
expect(Gitlab::Git::Compare).to receive(:new).and_call_original expect(Gitlab::Git::Compare).to receive(:new).and_call_original
mr_diff.diffs(ignore_whitespace_change: true) mr_diff.raw_diffs(ignore_whitespace_change: true)
end end
end end
...@@ -18,19 +18,19 @@ describe MergeRequestDiff, models: true do ...@@ -18,19 +18,19 @@ describe MergeRequestDiff, models: true do
before { mr_diff.update_attributes(st_diffs: '') } before { mr_diff.update_attributes(st_diffs: '') }
it 'returns an empty DiffCollection' do it 'returns an empty DiffCollection' do
expect(mr_diff.diffs).to be_a(Gitlab::Git::DiffCollection) expect(mr_diff.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
expect(mr_diff.diffs).to be_empty expect(mr_diff.raw_diffs).to be_empty
end end
end end
context 'when the raw diffs exist' do context 'when the raw diffs exist' do
it 'returns the diffs' do it 'returns the diffs' do
expect(mr_diff.diffs).to be_a(Gitlab::Git::DiffCollection) expect(mr_diff.raw_diffs).to be_a(Gitlab::Git::DiffCollection)
expect(mr_diff.diffs).not_to be_empty expect(mr_diff.raw_diffs).not_to be_empty
end end
context 'when the :paths option is set' do context 'when the :paths option is set' do
let(:diffs) { mr_diff.diffs(paths: ['files/ruby/popen.rb', 'files/ruby/popen.rb']) } let(:diffs) { mr_diff.raw_diffs(paths: ['files/ruby/popen.rb', 'files/ruby/popen.rb']) }
it 'only returns diffs that match the (old path, new path) given' do it 'only returns diffs that match the (old path, new path) given' do
expect(diffs.map(&:new_path)).to contain_exactly('files/ruby/popen.rb') expect(diffs.map(&:new_path)).to contain_exactly('files/ruby/popen.rb')
......
...@@ -136,7 +136,7 @@ describe MergeRequest, models: true do ...@@ -136,7 +136,7 @@ describe MergeRequest, models: true do
it 'delegates to the MR diffs' do it 'delegates to the MR diffs' do
merge_request.merge_request_diff = MergeRequestDiff.new merge_request.merge_request_diff = MergeRequestDiff.new
expect(merge_request.merge_request_diff).to receive(:diffs).with(options) expect(merge_request.merge_request_diff).to receive(:raw_diffs).with(options)
merge_request.raw_diffs(options) merge_request.raw_diffs(options)
end end
...@@ -161,7 +161,7 @@ describe MergeRequest, models: true do ...@@ -161,7 +161,7 @@ describe MergeRequest, models: true do
it 'delegates to the MR diffs' do it 'delegates to the MR diffs' do
merge_request.merge_request_diff = MergeRequestDiff.new merge_request.merge_request_diff = MergeRequestDiff.new
expect(merge_request.merge_request_diff).to receive(:diffs).with(hash_including(options)) expect(merge_request.merge_request_diff).to receive(:raw_diffs).with(hash_including(options))
merge_request.diffs(options) merge_request.diffs(options)
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