diff options
author | Sean McGivern <sean@gitlab.com> | 2016-07-27 12:42:18 +0100 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-08-12 23:24:43 +0300 |
commit | a1c79612172ce07c7b0de4c01fba8fa7369c71de (patch) | |
tree | fb8ad8e663fe2d30f43a2b0453d66fda6ce05301 /spec/controllers/projects/merge_requests_controller_spec.rb | |
parent | df2ed097b730c8ba0b79cac8cc3dbfcb0cf587cb (diff) | |
download | gitlab-ce-a1c79612172ce07c7b0de4c01fba8fa7369c71de.tar.gz |
Handle multiple merge conflict files in collection
Diffstat (limited to 'spec/controllers/projects/merge_requests_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/merge_requests_controller_spec.rb | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 69758494543..2cb89d71589 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -523,4 +523,69 @@ describe Projects::MergeRequestsController do end end end + + describe 'GET conflicts' do + let(:merge_request_with_conflicts) do + create(:merge_request, source_branch: 'conflict-a', target_branch: 'conflict-b', source_project: project) do |mr| + mr.mark_as_unmergeable + end + end + + context 'as JSON' do + before do + get :conflicts, + namespace_id: merge_request_with_conflicts.project.namespace.to_param, + project_id: merge_request_with_conflicts.project.to_param, + id: merge_request_with_conflicts.iid, + format: 'json' + end + + let(:json_response) { JSON.parse(response.body) } + + it 'includes meta info about the MR' do + expect(json_response['commit_message']).to include('Merge branch') + expect(json_response['commit_sha']).to match(/\h{40}/) + expect(json_response['source_branch']).to eq(merge_request_with_conflicts.source_branch) + expect(json_response['target_branch']).to eq(merge_request_with_conflicts.target_branch) + end + + it 'includes each file that has conflicts' do + filenames = json_response['files'].map { |file| file['new_path'] } + + expect(filenames).to contain_exactly('files/ruby/popen.rb', 'files/ruby/regex.rb') + end + + it 'splits files into sections with lines' do + json_response['files'].each do |file| + file['sections'].each do |section| + expect(section).to include('conflict', 'lines') + + section['lines'].each do |line| + if section['conflict'] + expect(line['type']).to be_in(['old', 'new']) + expect(line.values_at('old_line', 'new_line')).to contain_exactly(nil, a_kind_of(Integer)) + else + if line['type'].nil? + expect(line['old_line']).not_to eq(nil) + expect(line['new_line']).not_to eq(nil) + else + expect(line['type']).to eq('match') + expect(line['old_line']).to eq(nil) + expect(line['new_line']).to eq(nil) + end + end + end + end + end + end + + it 'has unique section IDs across files' do + section_ids = json_response['files'].flat_map do |file| + file['sections'].map { |section| section['id'] }.compact + end + + expect(section_ids.uniq).to eq(section_ids) + end + end + end end |