summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/conflict
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2016-07-27 12:42:18 +0100
committerFatih Acet <acetfatih@gmail.com>2016-08-12 23:24:43 +0300
commita1c79612172ce07c7b0de4c01fba8fa7369c71de (patch)
treefb8ad8e663fe2d30f43a2b0453d66fda6ce05301 /spec/lib/gitlab/conflict
parentdf2ed097b730c8ba0b79cac8cc3dbfcb0cf587cb (diff)
downloadgitlab-ce-a1c79612172ce07c7b0de4c01fba8fa7369c71de.tar.gz
Handle multiple merge conflict files in collection
Diffstat (limited to 'spec/lib/gitlab/conflict')
-rw-r--r--spec/lib/gitlab/conflict/file_collection_spec.rb24
-rw-r--r--spec/lib/gitlab/conflict/file_spec.rb13
-rw-r--r--spec/lib/gitlab/conflict/parser_spec.rb10
3 files changed, 35 insertions, 12 deletions
diff --git a/spec/lib/gitlab/conflict/file_collection_spec.rb b/spec/lib/gitlab/conflict/file_collection_spec.rb
new file mode 100644
index 00000000000..2a09adb2321
--- /dev/null
+++ b/spec/lib/gitlab/conflict/file_collection_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe Gitlab::Conflict::FileCollection, lib: true do
+ let(:merge_request) { create(:merge_request, source_branch: 'conflict-a', target_branch: 'conflict-b') }
+ let(:file_collection) { Gitlab::Conflict::FileCollection.new(merge_request) }
+
+ describe '#files' do
+ it 'returns an array of Conflict::Files' do
+ expect(file_collection.files).to all(be_an_instance_of(Gitlab::Conflict::File))
+ end
+ end
+
+ describe '#default_commit_message' do
+ it 'matches the format of the git CLI commit message' do
+ expect(file_collection.default_commit_message).to eq(<<EOM.chomp)
+Merge branch 'conflict-a' into 'conflict-b'
+
+# Conflicts:
+# files/ruby/popen.rb
+# files/ruby/regex.rb
+EOM
+ end
+ end
+end
diff --git a/spec/lib/gitlab/conflict/file_spec.rb b/spec/lib/gitlab/conflict/file_spec.rb
index 318d0d249d6..a9f2fed83aa 100644
--- a/spec/lib/gitlab/conflict/file_spec.rb
+++ b/spec/lib/gitlab/conflict/file_spec.rb
@@ -4,24 +4,21 @@ describe Gitlab::Conflict::File, lib: true do
let(:project) { create(:project) }
let(:repository) { project.repository }
let(:rugged) { repository.rugged }
- let(:their_ref) { their_commit.oid }
let(:their_commit) { rugged.branches['conflict-a'].target }
- let(:our_ref) { our_commit.oid }
+ let(:diff_refs) { Gitlab::Diff::DiffRefs.new(base_sha: their_commit.oid, head_sha: our_commit.oid) }
let(:our_commit) { rugged.branches['conflict-b'].target }
let(:index) { rugged.merge_commits(our_commit, their_commit) }
let(:conflict) { index.conflicts.last }
- let(:merge_file) { index.merge_file('files/ruby/regex.rb') }
- let(:conflict_file) { Gitlab::Conflict::File.new(merge_file, conflict, their_ref, our_ref, repository) }
+ let(:merge_file_result) { index.merge_file('files/ruby/regex.rb') }
+ let(:conflict_file) { Gitlab::Conflict::File.new(merge_file_result, conflict, diff_refs: diff_refs, repository: repository) }
describe '#highlighted_lines' do
def html_to_text(html)
- CGI.unescapeHTML(ActionView::Base.full_sanitizer.sanitize(html))
+ CGI.unescapeHTML(ActionView::Base.full_sanitizer.sanitize(html)).delete("\n")
end
it 'returns lines with rich_text' do
- conflict_file.highlighted_lines.each do |line|
- expect(line).to have_attributes(rich_text: an_instance_of(String))
- end
+ expect(conflict_file.highlighted_lines).to all(have_attributes(rich_text: a_kind_of(String)))
end
it 'returns lines with rich_text matching the text content of the line' do
diff --git a/spec/lib/gitlab/conflict/parser_spec.rb b/spec/lib/gitlab/conflict/parser_spec.rb
index 335da58e13c..1eda14f3e26 100644
--- a/spec/lib/gitlab/conflict/parser_spec.rb
+++ b/spec/lib/gitlab/conflict/parser_spec.rb
@@ -82,7 +82,9 @@ end
CONFLICT
end
- let(:lines) { parser.parse(text, 'files/ruby/regex.rb', 'files/ruby/regex.rb') }
+ let(:lines) do
+ parser.parse(text, our_path: 'files/ruby/regex.rb', their_path: 'files/ruby/regex.rb')
+ end
it 'sets our lines as new lines' do
expect(lines[8..13]).to all(have_attributes(type: 'new'))
@@ -117,7 +119,7 @@ CONFLICT
let(:path) { 'README.md' }
def parse_text(text)
- parser.parse(text, path, path)
+ parser.parse(text, our_path: path, their_path: path)
end
it 'raises UnexpectedDelimiter when there is a non-start delimiter first' do
@@ -171,8 +173,8 @@ CONFLICT
end
context 'when lines is blank' do
- it { expect(parser.parse('', 'README.md', 'README.md')).to eq([]) }
- it { expect(parser.parse(nil, 'README.md', 'README.md')).to eq([]) }
+ it { expect(parser.parse('', our_path: 'README.md', their_path: 'README.md')).to eq([]) }
+ it { expect(parser.parse(nil, our_path: 'README.md', their_path: 'README.md')).to eq([]) }
end
end
end