Welcome to mirror list, hosted at ThFree Co, Russian Federation.

file_spec.rb « conflict « git « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6eb7a7e394e07968567390d48cc3370e1a1de688 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Git::Conflict::File do
  let(:conflict) { { ancestor: { path: 'ancestor' }, theirs: { path: 'foo', mode: 33188 }, ours: { path: 'foo', mode: 33188 } } }
  let(:invalid_content) { described_class.new(nil, nil, conflict, (+"a\xC4\xFC").force_encoding(Encoding::ASCII_8BIT)) }
  let(:valid_content) { described_class.new(nil, nil, conflict, (+"Espa\xC3\xB1a").force_encoding(Encoding::ASCII_8BIT)) }

  describe '#lines' do
    context 'when the content contains non-UTF-8 characters' do
      it 'raises UnsupportedEncoding' do
        expect { invalid_content.lines }
          .to raise_error(described_class::UnsupportedEncoding)
      end
    end

    context 'when the content can be converted to UTF-8' do
      it 'sets lines to the lines' do
        expect(valid_content.lines).to eq([{
                                             full_line: 'España',
                                             type: nil,
                                             line_obj_index: 0,
                                             line_old: 1,
                                             line_new: 1
                                           }])
      end

      it 'sets the type to text' do
        expect(valid_content.type).to eq('text')
      end
    end
  end

  describe '#content' do
    context 'when the content contains non-UTF-8 characters' do
      it 'raises UnsupportedEncoding' do
        expect { invalid_content.content }
          .to raise_error(described_class::UnsupportedEncoding)
      end
    end

    context 'when the content can be converted to UTF-8' do
      it 'returns a valid UTF-8 string' do
        expect(valid_content.content).to eq('España')
        expect(valid_content.content).to be_valid_encoding
        expect(valid_content.content.encoding).to eq(Encoding::UTF_8)
      end
    end
  end

  describe '#path' do
    it 'returns our_path' do
      expect(valid_content.path).to eq(conflict[:ours][:path])
    end

    context 'when our_path is not present' do
      let(:conflict) { { ancestor: { path: 'ancestor' }, theirs: { path: 'theirs', mode: 33188 }, ours: { path: '', mode: 0 } } }

      it 'returns their_path' do
        expect(valid_content.path).to eq(conflict[:theirs][:path])
      end
    end
  end
end